You are here

protected function Messaging_Mail_Method::mail_build in Messaging 7

Rebuild message in Drupal mail format, right before sending

This mimics drupal_mail for finest access to properties

Parameters

$address: Email address to send to

$message: Message object

1 call to Messaging_Mail_Method::mail_build()
Messaging_Mail_Method::send_address in messaging_mail/messaging_mail.inc
Send message to address
1 method overrides Messaging_Mail_Method::mail_build()
Messaging_HTML_Mail_Method::mail_build in messaging_htmlmail/messaging_htmlmail.inc
Rebuild message in Drupal mail format, right before sending

File

messaging_mail/messaging_mail.inc, line 97
Drupal Messaging Framework - Send_Method class file

Class

Messaging_Mail_Method
Base class for mail sending methods

Code

protected function mail_build($address, $message) {
  $params = $this
    ->message_params($message);

  // Bundle up the variables into a structured array for altering.
  $mail = array(
    'headers' => $this
      ->mail_headers($message, $params),
    'id' => $message->module . '_' . $message->key,
    'module' => $message->module,
    'key' => $message->key,
    'to' => $params['send_bcc'] ? '' : $address,
    'from' => isset($params['from']) ? $params['from'] : $params['default_from'],
    'language' => $message
      ->get_language(),
    'params' => $params,
    'subject' => $message
      ->get_subject(),
    'body' => $this
      ->render_body($message
      ->get_template()
      ->build('body')),
    'attachments' => $message
      ->get_files(),
  );
  if ($params['send_bcc']) {
    $mail['headers']['Bcc'] = $address;
  }

  // Build the e-mail (get subject and body, allow additional headers) by
  // invoking hook_mail() on this module. We cannot use module_invoke() as
  // we need to have $message by reference in hook_mail().
  if (function_exists($function = $message->module . '_mail')) {
    $function($message->key, $mail, $params);
  }

  // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
  drupal_alter('mail', $mail);

  // Invoke drupal_mail without sending, then override headers
  return $mail;
}