You are here

function mimemail_phpmailer_send in PHPMailer 6

Same name and namespace in other branches
  1. 8.3 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
  2. 5.2 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
  3. 5 includes/mimemail.inc \mimemail_phpmailer_send()
  4. 6.3 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
  5. 6.2 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
  6. 7.4 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
  7. 7.3 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()

Send out an e-mail.

Parameters

$message: Mime Mail message array.

1 call to mimemail_phpmailer_send()
phpmailer_mailengine in ./phpmailer.module
Implementation of hook_mailengine().

File

includes/mimemail.inc, line 131

Code

function mimemail_phpmailer_send($message) {
  static $mail;
  if (!isset($mail)) {
    $mail = new DrupalPHPMailer();

    // Keep linefeed style in sync.
    $mail->LE = variable_get('mimemail_crlf', "\n");
  }

  // Extract and assign e-mail addresses required for SMTP.
  // Display names are not required. Leave header intact.
  // Parse 'From' e-mail address.
  $address = phpmailer_parse_address($message['from']);
  $mail->From = $address[0]['mail'];
  if (variable_get('phpmailer_debug_email', '') === '') {

    // Set recipients.
    foreach (phpmailer_parse_address($message['address']) as $address) {
      $mail
        ->AddAddress($address['mail']);
    }

    // Extract CCs and BCCs from headers.
    if (isset($message['headers']['CC'])) {
      foreach (phpmailer_parse_address($message['headers']['CC']) as $address) {
        $mail
          ->AddCC($address['mail']);
      }
    }
    if (isset($message['headers']['BCC'])) {
      foreach (phpmailer_parse_address($message['headers']['BCC']) as $address) {
        $mail
          ->AddBCC($address['mail']);
      }
    }
  }
  else {

    // Reroute to debug e-mail address.
    $message['address'] = variable_get('phpmailer_debug_email', '');
    $mail
      ->AddAddress($message['address']);
  }
  unset($message['headers']['CC'], $message['headers']['BCC']);
  if ($mail->SMTPDebug) {
    ob_start();
  }
  $message['headers']['Date'] = $mail
    ->RFCDate();
  if ($message['address']) {
    $message['headers']['To'] = $message['address'];
  }
  $message['headers']['Subject'] = $message['subject'];

  // FIXME SpamAssassin says INVALID_MSGID to PHPMailer's generated Message-ID. 06/04/2009 smk
  //  if (!isset($message['headers']['Message-ID'])) {
  //    $message['headers']['Message-ID'] = sprintf("<%s@%s>", md5(uniqid(time())), $mail->ServerHostname());
  //  }
  $header = mimemail_rfc_headers($message['headers']) . $mail->LE . $mail->LE;
  if (!($result = $mail
    ->SmtpSend($header, $message['body']))) {
    watchdog('phpmailer', $mail->ErrorInfo, NULL, WATCHDOG_ERROR);
  }

  // Reset object properties.
  $mail
    ->Reset();
  if ($mail->SMTPDebug) {
    if ($debug = ob_get_contents()) {
      drupal_set_message($debug);
    }
    ob_end_clean();
  }
  return $result;
}