You are here

public function MandrillTestAPI::sendTemplate in Mandrill 8

Sends a templated Mandrill message.

This function checks for appropriate settings in the message, then uses the template API call to send the message if the settings are valid.

Parameters

array $message:

string $template_id:

array $template_content:

Return value

array Array of message objects, one per recipient.

Overrides MandrillAPI::sendTemplate

File

src/MandrillTestAPI.php, line 151

Class

MandrillTestAPI
Overrides functions in the Mandrill API service for testing.

Namespace

Drupal\mandrill

Code

public function sendTemplate($message, $template_id, $template_content) {
  if (!isset($message['to']) || empty($message['to'])) {
    return $this
      ->getErrorResponse(12, 'ValidationError', 'No recipients defined.');
  }
  $response = array();
  $templates = $this
    ->getTemplates();
  $matched_template = NULL;
  foreach ($templates as $template) {
    if ($template['name'] == $template_id) {
      $matched_template = $template;
      continue;
    }
  }
  if ($matched_template == NULL) {
    return $this
      ->getErrorResponse(12, 'Unknown_Template', 'No template with name: ' . $template_id);
  }
  $recipients = mandrill_get_to($message['to']);
  foreach ($recipients as $recipient) {
    $recipient_response = array(
      'email' => $recipient['email'],
      'status' => 'sent',
      'reject_reason' => '',
      '_id' => uniqid(),
    );
    $response[] = $recipient_response;
  }
  return $response;
}