You are here

protected function MandrillService::handleSendResponse in Mandrill 8

Response handler for sent messages.

Parameters

array $response: Response from the Mandrill API.

array $message: The sent message.

Return value

bool TRUE if the message was sent or queued without error.

2 calls to MandrillService::handleSendResponse()
MandrillService::send in src/MandrillService.php
Abstracts sending of messages, allowing queueing option.
MandrillTemplateService::send in modules/mandrill_template/src/MandrillTemplateService.php
Abstracts sending of messages, allowing queueing option.
1 method overrides MandrillService::handleSendResponse()
MandrillTestService::handleSendResponse in src/MandrillTestService.php
Response handler for sent messages.

File

src/MandrillService.php, line 170

Class

MandrillService
Mandrill Service.

Namespace

Drupal\mandrill

Code

protected function handleSendResponse($response, $message) {
  if (!isset($response['status'])) {
    foreach ($response as $result) {

      // Allow other modules to react based on a send result.
      \Drupal::moduleHandler()
        ->invokeAll('mandrill_mailsend_result', [
        $result,
      ], [
        $message,
      ]);
      switch ($result['status']) {
        case "error":
        case "invalid":
        case "rejected":
          $to = isset($result['email']) ? $result['email'] : 'recipient';
          $status = isset($result['status']) ? $result['status'] : 'message';
          $error_message = isset($result['message']) ? $result['message'] : 'no message';
          if (!isset($result['message']) && isset($result['reject_reason'])) {
            $error_message = $result['reject_reason'];
          }
          $this->log
            ->error('Failed sending email from %from to %to. @status: @message', array(
            '%from' => $message['from_email'],
            '%to' => $to,
            '@status' => $status,
            '@message' => $error_message,
          ));
          return FALSE;
        case "queued":
          $this->log
            ->info('Email from %from to %to queued by Mandrill App.', array(
            '%from' => $message['from_email'],
            '%to' => $result['email'],
          ));
          break;
      }
    }
  }
  else {
    $this->log
      ->warning('Mail send failed with status %status: code %code, %name, %message', array(
      '%status' => $response['status'],
      '%code' => $response['code'],
      '%name' => $response['name'],
      '%message' => $response['message'],
    ));
    return FALSE;
  }
  return TRUE;
}