You are here

function queue_mail_send in Queue Mail 7

Same name and namespace in other branches
  1. 5 queue_mail.module \queue_mail_send()
  2. 6 queue_mail.module \queue_mail_send()

Email sending function, called via Drupal's queue processing.

The body of this function is basically the latter half of drupal_mail(), after the call to allow other modules to alter the message, at which point queue_mail_mail_alter() popped the $message into the queue which is being processed now.

Parameters

$message: The message, as built and altered by drupal_mail().

See also

drupal_mail()

queue_mail_mail_alter()

1 string reference to 'queue_mail_send'
queue_mail_cron_queue_info in ./queue_mail.module
Implements hook_cron_queue_info().

File

./queue_mail.module, line 96
The Queue Mail module.

Code

function queue_mail_send($message = array()) {

  // Invoke hook_queue_mail_send_alter() to allow all modules to alter the
  // queued e-mail.
  drupal_alter('queue_mail_send', $message);

  // Retrieve the responsible implementation for this message.
  $system = drupal_mail_system($message['module'], $message['key']);

  // Format the message body.
  $message = $system
    ->format($message);

  // The original caller requested sending. Sending was canceled by one or
  // more hook_mail_alter() implementations. We set 'result' to NULL, because
  // FALSE indicates an error in sending.
  if (empty($message['send'])) {
    $message['result'] = NULL;
  }
  else {
    $message['result'] = $system
      ->mail($message);

    // Log errors and throw exception so that failed item remains in queue.
    if (!$message['result']) {
      throw new Exception(t('Error sending e-mail (from %from to %to).', array(
        '%from' => $message['from'],
        '%to' => $message['to'],
      )));
    }
  }
  return $message;
}