function mimemail_phpmailer_send in PHPMailer 8.3
Same name and namespace in other branches
- 5.2 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
- 5 includes/mimemail.inc \mimemail_phpmailer_send()
- 6.3 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
- 6 includes/mimemail.inc \mimemail_phpmailer_send()
- 6.2 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
- 7.4 includes/phpmailer.mimemail.inc \mimemail_phpmailer_send()
- 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/
phpmailer.mimemail.inc, line 16 - Implements PHPMailer support on behalf of Mime Mail module.
Code
function mimemail_phpmailer_send($message) {
static $mail;
if (!isset($mail)) {
$mail = new DrupalPHPMailer();
// Keep linefeed style in sync.
/**
* @todo Need to find out where this variable comes from.
*/
// $mail->LE = variable_get('mimemail_crlf', "\n");
}
try {
// Extract and assign e-mail addresses required for SMTP.
// Display names are usually not required. Leave header intact.
// Parse 'From' e-mail address.
$from = phpmailer_parse_address($message['from']);
$from = reset($from);
$mail->From = $from['mail'];
if ($from['name'] != '') {
$mail->FromName = $from['name'];
}
if (\Drupal::config('system.maintenance')
->get('phpmailer_debug_email') === '') {
// Set recipients.
foreach (phpmailer_parse_address($message['to']) 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['to'] = \Drupal::config('system.maintenance')
->get('phpmailer_debug_email');
$mail
->AddAddress($message['to']);
}
unset($message['headers']['Cc'], $message['headers']['Bcc']);
$message['headers']['Date'] = $mail
->RFCDate();
if ($message['to']) {
$message['headers']['To'] = $message['to'];
}
// If no Reply-To header has been explicitly set, use the From address to be
// able to respond to e-mails sent via Google Mail.
if (!isset($message['headers']['Reply-To']) && \Drupal::config('phpmailer.settings')
->get('smtp_always_replyto')) {
$message['headers']['Reply-To'] = $from['mail'];
}
$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;
return $mail
->SmtpSend($header, $message['body']);
} catch (phpmailerException $e) {
drupal_set_message(t('Sending of at least one e-mail failed. The error returned was:<br />@error.', [
'@error' => $e
->getMessage(),
]), 'error');
\Drupal::logger('phpmailer')
->error($e
->getMessage());
return FALSE;
}
}