View source
<?php
module_load_include('php', 'phpmailer', 'phpmailer/class.phpmailer');
class MimeMailPHPMailer extends PHPMailer {
var $ReturnPath = '';
function MimeMailPHPMailer() {
$this
->IsSMTP();
$this
->Reset();
$protocol = variable_get('smtp_protocol', '');
$this->Host = $protocol . variable_get('smtp_host', '');
if ($backup = variable_get('smtp_hostbackup', '')) {
$this->Host .= ';' . $protocol . $backup;
}
$this->Port = variable_get('smtp_port', '25');
$this->Username = variable_get('smtp_username', '');
$this->Password = variable_get('smtp_password', '');
$this->SMTPAuth = (bool) ($this->Username != '' && $this->Password != '');
$this->SMTPKeepAlive = variable_get('smtp_keepalive', 0);
$this->SMTPDebug = variable_get('smtp_debug', 0);
$this->PluginDir = drupal_get_path('module', 'phpmailer') . '/phpmailer/';
}
function Reset() {
$this
->ClearAllRecipients();
$this
->ClearAttachments();
$this
->ClearCustomHeaders();
$this->Priority = 3;
$this->CharSet = variable_get('smtp_charset', 'utf-8');
$this->ContentType = 'text/plain';
$this->Encoding = '8bit';
$this->ErrorInfo = '';
$from_name = variable_get('smtp_fromname', '');
if ($from_name == '') {
$from_name = variable_get('site_name', 'Drupal');
}
$this->FromName = $from_name;
$this->Sender = '';
$this->MessageID = '';
$this->ReturnPath = '';
}
function SetLanguage($lang_type = 'en', $lang_path = 'language/') {
$PHPMAILER_LANG = array();
$PHPMAILER_LANG['provide_address'] = 'You must provide at least one recipient email address.';
$PHPMAILER_LANG['mailer_not_supported'] = ' mailer is not supported.';
$PHPMAILER_LANG['execute'] = 'Could not execute: ';
$PHPMAILER_LANG['instantiate'] = 'Could not instantiate mail function.';
$PHPMAILER_LANG['authenticate'] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG['from_failed'] = 'The following From address failed: ';
$PHPMAILER_LANG['recipients_failed'] = 'SMTP Error: The following recipients failed: ';
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG['connect_host'] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG['file_access'] = 'Could not access file: ';
$PHPMAILER_LANG['file_open'] = 'File Error: Could not open file: ';
$PHPMAILER_LANG['encoding'] = 'Unknown encoding: ';
$PHPMAILER_LANG['signing'] = 'Signing Error: ';
$this->language = $PHPMAILER_LANG;
return TRUE;
}
function CreateHeader() {
$old_sender = $this->Sender;
if ($this->ReturnPath != '') {
$this->Sender = $this->ReturnPath;
}
$result = parent::CreateHeader();
$this->Sender = $old_sender;
return $result;
}
function RFCDate() {
$tz = date('Z');
$tzs = $tz < 0 ? '-' : '+';
$tz = abs($tz);
$tz = (int) ($tz / 3600) * 100 + $tz % 3600 / 60;
$result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
return $result;
}
}
function mimemail_phpmailer_send($message) {
static $mail;
if (!isset($mail)) {
$mail = new DrupalPHPMailer();
$mail->LE = variable_get('mimemail_crlf', "\n");
}
$address = phpmailer_parse_address($message['from']);
$mail->From = $address[0]['mail'];
if (variable_get('phpmailer_debug_email', '') === '') {
foreach (phpmailer_parse_address($message['address']) as $address) {
$mail
->AddAddress($address['mail']);
}
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 {
$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'];
$header = mimemail_rfc_headers($message['headers']) . $mail->LE . $mail->LE;
if (!($result = $mail
->SmtpSend($header, $message['body']))) {
watchdog('phpmailer', $mail->ErrorInfo, NULL, WATCHDOG_ERROR);
}
$mail
->Reset();
if ($mail->SMTPDebug) {
if ($debug = ob_get_contents()) {
drupal_set_message($debug);
}
ob_end_clean();
}
return $result;
}