You are here

function _views_send_prepare_mail in Views Send 6

Same name and namespace in other branches
  1. 8 views_send.module \_views_send_prepare_mail()
  2. 7 views_send.module \_views_send_prepare_mail()

Perform all alteration and preparation before spooling.

Parameters

$from_name: String holding the Sender's name.

$from_mail: String holding the Sender's e-mail.

$to_name: String holding the Recipient's name.

$to_mail: String holding the Recipient's e-mail.

$subject: String with the e-mail subject. This argument can be altered here.

$body: Text with the e-mail body. This argument can be altered here.

$headers: Associative array with e-mail headers. This argument can be altered here.

$format: String with the e-mail format.

1 call to _views_send_prepare_mail()
views_send_mail_action in ./views_send.module
Main action callback.

File

./views_send.module, line 748
The Views Send module.

Code

function _views_send_prepare_mail($from_name, $from_mail, $to_name, $to_mail, &$subject, &$body, &$headers, $format, $attachments) {

  /**
   * TODO: In the future, this module will be able to send an existing node.
   * $key will have to make the difference. A value when we pickup a node, other
   * when user inputs the subject & body of the message.
   */
  $key = 'direct';

  // Build message parameters.
  $params = array();
  $params['from_name'] = $from_name;
  $params['from_mail'] = $from_mail;
  $params['from_formatted'] = _views_send_format_address($from_mail, $from_name);
  $params['to_name'] = $to_name;
  $params['to_mail'] = $to_mail;
  $params['to_formatted'] = _views_send_format_address($to_mail, $to_name);
  $params['subject'] = $subject;
  $params['body'] = $body;
  $params['headers'] = $headers;

  // Call Drupal standard mail function, but without sending.
  $mail = drupal_mail('views_send', $key, $params['to_formatted'], NULL, $params, $params['from_formatted'], FALSE);

  // Add additional Mime Mail processing.
  if (VIEWS_SEND_MIMEMAIL) {
    $plain = $format == VIEWS_SEND_FORMAT_PLAIN;
    $plain_text = $plain ? $mail['body'] : _views_send_html_to_text($mail['body'], TRUE);
    $mail = mimemail($mail['from'], $mail['to'], $mail['subject'], $mail['body'], $plain, $mail['headers'], $plain_text, $attachments, 'views_send_' . $key, FALSE);

    // From: header may be broken after mimemail_prepare().
    $mail['headers']['From'] = _views_send_format_address($from_mail, $from_name);

    // We want to spool the Subject decoded.
    $mail['subject'] = mime_header_decode($mail['subject']);
  }
  $subject = $mail['subject'];
  $body = $mail['body'];
  $headers = $mail['headers'];
}