You are here

static function Messaging_Method_Mail::mail_build in Messaging 6.4

Rebuild message in Drupal mail format, right before sending

Parameters

$destination: Email destination

$message: Message object

$params: Aditional parameters

$alter: Whether to run the mail_alter hook

File

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

Class

Messaging_Method_Mail
Base class for mail sending methods

Code

static function mail_build($destination, $message, $params = array(), $alter = TRUE) {

  // Build parameters and headers if not previously built
  if (!$params || empty($params['headers'])) {
    $params = self::mail_params($message, $params);
  }

  // Build the mail object, mimic drupal_mail() format
  $mail = array(
    'id' => $params['id'],
    'to' => $destination,
    'from' => $params['from'],
    'language' => $message
      ->get_language(),
    'subject' => $message
      ->get_subject(),
    'body' => $message
      ->get_body(),
    'headers' => $params['headers'],
    'attachments' => $message
      ->get_files(),
    'params' => $params,
  );

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