| 1 |
<?php |
<?php |
| 2 |
// $Id: phpmailer.class.inc,v 1.1.2.1.2.9 2009/11/04 20:14:40 smk Exp $ |
// $Id: phpmailer.class.inc,v 1.1.2.1.2.10 2009/11/12 10:18:10 smk Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 14 |
*/ |
*/ |
| 15 |
class DrupalPHPMailer extends PHPMailer { |
class DrupalPHPMailer extends PHPMailer { |
| 16 |
/** |
/** |
| 17 |
* Stores the Return-Path, which can be different from Sender. |
* Stores the Return-Path, which may be different from Sender. |
| 18 |
*/ |
*/ |
| 19 |
public $ReturnPath = ''; |
public $ReturnPath = ''; |
| 20 |
|
|
| 22 |
* Constructor. |
* Constructor. |
| 23 |
*/ |
*/ |
| 24 |
public function __construct() { |
public function __construct() { |
| 25 |
// Throw exceptions instead of echoing error messages (since 5.0.0). |
// Throw exceptions instead of dying (since 5.0.0). |
| 26 |
parent::__construct(TRUE); |
parent::__construct(TRUE); |
| 27 |
|
|
| 28 |
$this->IsSMTP(); |
$this->IsSMTP(); |
| 48 |
} |
} |
| 49 |
|
|
| 50 |
/** |
/** |
| 51 |
* Wrapper around PHPMailer::Send() that properly handles exceptions. |
* Create the message and send it. |
| 52 |
|
* |
| 53 |
|
* Wrapper around PHPMailer::Send() that catches any error messages and |
| 54 |
|
* passes them to Drupal. |
| 55 |
*/ |
*/ |
| 56 |
public function Send() { |
public function Send() { |
| 57 |
try { |
try { |
| 60 |
catch (phpmailerException $e) { |
catch (phpmailerException $e) { |
| 61 |
// Provide a more helpful error message. |
// Provide a more helpful error message. |
| 62 |
drupal_set_message(t('Sending of at least one e-mail failed. The error returned was:<br />@error.', array('@error' => $e->getMessage())), 'error'); |
drupal_set_message(t('Sending of at least one e-mail failed. The error returned was:<br />@error.', array('@error' => $e->getMessage())), 'error'); |
| 63 |
|
watchdog('phpmailer', $e->getMessage(), WATCHDOG_ERROR); |
| 64 |
$result = FALSE; |
$result = FALSE; |
| 65 |
} |
} |
| 66 |
return $result; |
return $result; |
| 67 |
} |
} |
| 68 |
|
|
| 69 |
/** |
/** |
| 70 |
|
* Send mail via SMTP. |
| 71 |
|
* |
| 72 |
|
* Wrapper around PHPMailer::SmtpSend() that resets mail properties to their |
| 73 |
|
* defaults after sending and passes any error messages to Drupal. |
| 74 |
|
*/ |
| 75 |
|
public function SmtpSend($header, $body) { |
| 76 |
|
if ($this->SMTPDebug) { |
| 77 |
|
ob_start(); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
try { |
| 81 |
|
$result = parent::SmtpSend($header, $body); |
| 82 |
|
} |
| 83 |
|
catch (phpmailerException $e) { |
| 84 |
|
// Provide a more helpful error message. |
| 85 |
|
drupal_set_message(t('Sending of at least one e-mail failed. The error returned was:<br />@error.', array('@error' => $e->getMessage())), 'error'); |
| 86 |
|
watchdog('phpmailer', $e->getMessage(), NULL, WATCHDOG_ERROR); |
| 87 |
|
$result = FALSE; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
if ($this->SMTPDebug) { |
| 91 |
|
if ($debug = ob_get_contents()) { |
| 92 |
|
drupal_set_message($debug); |
| 93 |
|
} |
| 94 |
|
ob_end_clean(); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
// Reinitialize properties. |
| 98 |
|
$this->Reset(); |
| 99 |
|
|
| 100 |
|
return $result; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
/** |
| 104 |
* (Re-)initialize properties after sending mail. |
* (Re-)initialize properties after sending mail. |
| 105 |
*/ |
*/ |
| 106 |
public function Reset() { |
public function Reset() { |
| 130 |
* Destructor. |
* Destructor. |
| 131 |
*/ |
*/ |
| 132 |
public function __destruct() { |
public function __destruct() { |
| 133 |
|
// Required when using SMTP keep-alive. |
| 134 |
$this->SmtpClose(); |
$this->SmtpClose(); |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
/** |
/** |
|
* Sends mail via SMTP. |
|
|
*/ |
|
|
public function SmtpSend($header, $body) { |
|
|
$result = parent::SmtpSend($header, $body); |
|
|
// Reinitialize properties. |
|
|
$this->Reset(); |
|
|
return $result; |
|
|
} |
|
|
|
|
|
/** |
|
| 138 |
* Provide more user-friendly error messages. |
* Provide more user-friendly error messages. |
| 139 |
* |
* |
| 140 |
* Note: messages should not end with a dot. |
* Note: messages should not end with a dot. |
| 150 |
'authenticate' => t('SMTP error: could not authenticate'), |
'authenticate' => t('SMTP error: could not authenticate'), |
| 151 |
'smtp_connect_failed' => t('SMTP error: could not connect to SMTP host'), |
'smtp_connect_failed' => t('SMTP error: could not connect to SMTP host'), |
| 152 |
'connect_host' => t('SMTP error: could not connect to SMTP host'), |
'connect_host' => t('SMTP error: could not connect to SMTP host'), |
| 153 |
'from_failed' => t('The following sender failed: '), // non-admin |
'from_failed' => t('The following sender address failed: '), // non-admin |
| 154 |
'recipients_failed' => t('The following recipients failed: '), // non-admin |
'recipients_failed' => t('The following recipient addresses failed: '), // non-admin |
| 155 |
'data_not_accepted' => t('SMTP error: data not accepted'), |
'data_not_accepted' => t('SMTP error: data not accepted'), |
| 156 |
'smtp_error' => t('SMTP server error: '), |
'smtp_error' => t('SMTP server error: '), |
| 157 |
|
|
| 168 |
} |
} |
| 169 |
|
|
| 170 |
/** |
/** |
| 171 |
* Assembles message header. |
* Assemble the message header. |
| 172 |
* |
* |
| 173 |
* PHPMailer always sets Return-Path to Sender, we want more flexibility. |
* PHPMailer always sets Return-Path to Sender, we want more flexibility. |
| 174 |
*/ |
*/ |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
/** |
/** |
| 187 |
* Returns the proper RFC 822 formatted date. |
* Public wrapper around PHPMailer::RFCDate(). |
| 188 |
*/ |
*/ |
| 189 |
public static function RFCDate() { |
public static function RFCDate() { |
| 190 |
$tz = date('Z'); |
$tz = date('Z'); |