You are here

function messaging_mail_prepare in Messaging 6

Same name and namespace in other branches
  1. 6.2 messaging.mail.inc \messaging_mail_prepare()
  2. 6.3 messaging.mail.inc \messaging_mail_prepare()

Rebuild message in Drupal mail format

Parameters

$destination: Email destination

$message: Message object

$params: Aditional parameters

$alter: Whether to run the mail_alter hook

3 calls to messaging_mail_prepare()
messaging_mail_send_msg in messaging_mail/messaging_mail.module
Send mail message to user account
messaging_mime_mail_send_msg in messaging_mime_mail/messaging_mime_mail.module
Send mime mail message to user account
messaging_phpmailer_send_msg in messaging_phpmailer/messaging_phpmailer.module
Send mail message to user account. Supports bulk sending

File

./messaging.mail.inc, line 22
Common library for mail methods

Code

function messaging_mail_prepare($destination, $message, $params, $alter = TRUE) {

  // The message 'from' will depend on message sender if present, otherwise default to site mail
  $default_from = variable_get('site_mail', ini_get('sendmail_from'));
  if (empty($params['from'])) {
    if (!empty($message->sender_account) && !empty($message->sender_account->mail)) {
      $from = check_plain($message->sender_account->name) . ' <' . $message->sender_account->mail . '>';
    }
    elseif (!empty($message->sender_name) && $default_from) {
      $from = check_plain($message->sender_name) . ' <' . $default_from . '>';
    }
    else {
      $from = $default_from;
    }
    $params['from'] = $from;
  }
  else {
    $from = $params['from'];
  }

  // Build the mail object, mimic drupal_mail() format
  $mail = array(
    'id' => 'messaging_' . (!empty($message->type) ? 'message-' . $message->type : 'message'),
    'to' => $destination,
    'from' => $from,
    'language' => !empty($message->language) ? $message->language : language_default(),
    'params' => $params,
    'subject' => $message->subject,
    'body' => $message->body,
    'headers' => messaging_mail_headers($message, $params),
  );

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