|
@@ -30,7 +30,7 @@ class SMTP
|
|
|
* The PHPMailer SMTP version number.
|
|
* The PHPMailer SMTP version number.
|
|
|
* @var string
|
|
* @var string
|
|
|
*/
|
|
*/
|
|
|
- const VERSION = '5.2.22';
|
|
|
|
|
|
|
+ const VERSION = '5.2.23';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SMTP line break constant.
|
|
* SMTP line break constant.
|
|
@@ -81,7 +81,7 @@ class SMTP
|
|
|
* @deprecated Use the `VERSION` constant instead
|
|
* @deprecated Use the `VERSION` constant instead
|
|
|
* @see SMTP::VERSION
|
|
* @see SMTP::VERSION
|
|
|
*/
|
|
*/
|
|
|
- public $Version = '5.2.22';
|
|
|
|
|
|
|
+ public $Version = '5.2.23';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SMTP server port number.
|
|
* SMTP server port number.
|
|
@@ -150,16 +150,16 @@ class SMTP
|
|
|
*/
|
|
*/
|
|
|
public $Timelimit = 300;
|
|
public $Timelimit = 300;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @var array patterns to extract smtp transaction id from smtp reply
|
|
|
|
|
- * Only first capture group will be use, use non-capturing group to deal with it
|
|
|
|
|
- * Extend this class to override this property to fulfil your needs.
|
|
|
|
|
- */
|
|
|
|
|
- protected $smtp_transaction_id_patterns = array(
|
|
|
|
|
- 'exim' => '/[0-9]{3} OK id=(.*)/',
|
|
|
|
|
- 'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
|
|
|
|
|
- 'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/'
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @var array patterns to extract smtp transaction id from smtp reply
|
|
|
|
|
+ * Only first capture group will be use, use non-capturing group to deal with it
|
|
|
|
|
+ * Extend this class to override this property to fulfil your needs.
|
|
|
|
|
+ */
|
|
|
|
|
+ protected $smtp_transaction_id_patterns = array(
|
|
|
|
|
+ 'exim' => '/[0-9]{3} OK id=(.*)/',
|
|
|
|
|
+ 'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
|
|
|
|
|
+ 'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* The socket for the server connection.
|
|
* The socket for the server connection.
|
|
@@ -231,8 +231,7 @@ class SMTP
|
|
|
preg_replace('/[\r\n]+/', '', $str),
|
|
preg_replace('/[\r\n]+/', '', $str),
|
|
|
ENT_QUOTES,
|
|
ENT_QUOTES,
|
|
|
'UTF-8'
|
|
'UTF-8'
|
|
|
- )
|
|
|
|
|
- . "<br>\n";
|
|
|
|
|
|
|
+ ) . "<br>\n";
|
|
|
break;
|
|
break;
|
|
|
case 'echo':
|
|
case 'echo':
|
|
|
default:
|
|
default:
|
|
@@ -242,7 +241,7 @@ class SMTP
|
|
|
"\n",
|
|
"\n",
|
|
|
"\n \t ",
|
|
"\n \t ",
|
|
|
trim($str)
|
|
trim($str)
|
|
|
- )."\n";
|
|
|
|
|
|
|
+ ) . "\n";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -276,7 +275,8 @@ class SMTP
|
|
|
}
|
|
}
|
|
|
// Connect to the SMTP server
|
|
// Connect to the SMTP server
|
|
|
$this->edebug(
|
|
$this->edebug(
|
|
|
- "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
|
|
|
|
|
|
|
+ "Connection: opening to $host:$port, timeout=$timeout, options=" .
|
|
|
|
|
+ var_export($options, true),
|
|
|
self::DEBUG_CONNECTION
|
|
self::DEBUG_CONNECTION
|
|
|
);
|
|
);
|
|
|
$errno = 0;
|
|
$errno = 0;
|
|
@@ -362,14 +362,14 @@ class SMTP
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Begin encrypted connection
|
|
// Begin encrypted connection
|
|
|
- if (!stream_socket_enable_crypto(
|
|
|
|
|
|
|
+ set_error_handler(array($this, 'errorHandler'));
|
|
|
|
|
+ $crypto_ok = stream_socket_enable_crypto(
|
|
|
$this->smtp_conn,
|
|
$this->smtp_conn,
|
|
|
true,
|
|
true,
|
|
|
$crypto_method
|
|
$crypto_method
|
|
|
- )) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+ restore_error_handler();
|
|
|
|
|
+ return $crypto_ok;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -398,8 +398,7 @@ class SMTP
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (array_key_exists('EHLO', $this->server_caps)) {
|
|
if (array_key_exists('EHLO', $this->server_caps)) {
|
|
|
- // SMTP extensions are available. Let's try to find a proper authentication method
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // SMTP extensions are available; try to find a proper authentication method
|
|
|
if (!array_key_exists('AUTH', $this->server_caps)) {
|
|
if (!array_key_exists('AUTH', $this->server_caps)) {
|
|
|
$this->setError('Authentication is not allowed at this stage');
|
|
$this->setError('Authentication is not allowed at this stage');
|
|
|
// 'at this stage' means that auth may be allowed after the stage changes
|
|
// 'at this stage' means that auth may be allowed after the stage changes
|
|
@@ -424,7 +423,7 @@ class SMTP
|
|
|
$this->setError('No supported authentication methods found');
|
|
$this->setError('No supported authentication methods found');
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
|
|
|
|
|
|
|
+ self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($authtype, $this->server_caps['AUTH'])) {
|
|
if (!in_array($authtype, $this->server_caps['AUTH'])) {
|
|
@@ -550,7 +549,7 @@ class SMTP
|
|
|
* Works like hash_hmac('md5', $data, $key)
|
|
* Works like hash_hmac('md5', $data, $key)
|
|
|
* in case that function is not available
|
|
* in case that function is not available
|
|
|
* @param string $data The data to hash
|
|
* @param string $data The data to hash
|
|
|
- * @param string $key The key to hash with
|
|
|
|
|
|
|
+ * @param string $key The key to hash with
|
|
|
* @access protected
|
|
* @access protected
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
@@ -893,7 +892,8 @@ class SMTP
|
|
|
$code_ex = (count($matches) > 2 ? $matches[2] : null);
|
|
$code_ex = (count($matches) > 2 ? $matches[2] : null);
|
|
|
// Cut off error code from each response line
|
|
// Cut off error code from each response line
|
|
|
$detail = preg_replace(
|
|
$detail = preg_replace(
|
|
|
- "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
|
|
|
|
|
|
|
+ "/{$code}[ -]" .
|
|
|
|
|
+ ($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . "/m",
|
|
|
'',
|
|
'',
|
|
|
$this->last_reply
|
|
$this->last_reply
|
|
|
);
|
|
);
|
|
@@ -1105,7 +1105,7 @@ class SMTP
|
|
|
// Now check if reads took too long
|
|
// Now check if reads took too long
|
|
|
if ($endtime and time() > $endtime) {
|
|
if ($endtime and time() > $endtime) {
|
|
|
$this->edebug(
|
|
$this->edebug(
|
|
|
- 'SMTP -> get_lines(): timelimit reached ('.
|
|
|
|
|
|
|
+ 'SMTP -> get_lines(): timelimit reached (' .
|
|
|
$this->Timelimit . ' sec)',
|
|
$this->Timelimit . ' sec)',
|
|
|
self::DEBUG_LOWLEVEL
|
|
self::DEBUG_LOWLEVEL
|
|
|
);
|
|
);
|
|
@@ -1208,42 +1208,44 @@ class SMTP
|
|
|
* Reports an error number and string.
|
|
* Reports an error number and string.
|
|
|
* @param integer $errno The error number returned by PHP.
|
|
* @param integer $errno The error number returned by PHP.
|
|
|
* @param string $errmsg The error message returned by PHP.
|
|
* @param string $errmsg The error message returned by PHP.
|
|
|
|
|
+ * @param string $errfile The file the error occurred in
|
|
|
|
|
+ * @param integer $errline The line number the error occurred on
|
|
|
*/
|
|
*/
|
|
|
- protected function errorHandler($errno, $errmsg)
|
|
|
|
|
|
|
+ protected function errorHandler($errno, $errmsg, $errfile = '', $errline = 0)
|
|
|
{
|
|
{
|
|
|
- $notice = 'Connection: Failed to connect to server.';
|
|
|
|
|
|
|
+ $notice = 'Connection failed.';
|
|
|
$this->setError(
|
|
$this->setError(
|
|
|
$notice,
|
|
$notice,
|
|
|
$errno,
|
|
$errno,
|
|
|
$errmsg
|
|
$errmsg
|
|
|
);
|
|
);
|
|
|
$this->edebug(
|
|
$this->edebug(
|
|
|
- $notice . ' Error number ' . $errno . '. "Error notice: ' . $errmsg,
|
|
|
|
|
|
|
+ $notice . ' Error #' . $errno . ': ' . $errmsg . " [$errfile line $errline]",
|
|
|
self::DEBUG_CONNECTION
|
|
self::DEBUG_CONNECTION
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Will return the ID of the last smtp transaction based on a list of patterns provided
|
|
|
|
|
- * in SMTP::$smtp_transaction_id_patterns.
|
|
|
|
|
- * If no reply has been received yet, it will return null.
|
|
|
|
|
- * If no pattern has been matched, it will return false.
|
|
|
|
|
- * @return bool|null|string
|
|
|
|
|
- */
|
|
|
|
|
- public function getLastTransactionID()
|
|
|
|
|
- {
|
|
|
|
|
- $reply = $this->getLastReply();
|
|
|
|
|
-
|
|
|
|
|
- if (empty($reply)) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- foreach($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
|
|
|
|
|
- if(preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
|
|
|
|
|
- return $matches[1];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Will return the ID of the last smtp transaction based on a list of patterns provided
|
|
|
|
|
+ * in SMTP::$smtp_transaction_id_patterns.
|
|
|
|
|
+ * If no reply has been received yet, it will return null.
|
|
|
|
|
+ * If no pattern has been matched, it will return false.
|
|
|
|
|
+ * @return bool|null|string
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getLastTransactionID()
|
|
|
|
|
+ {
|
|
|
|
|
+ $reply = $this->getLastReply();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($reply)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
|
|
|
|
|
+ if (preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
|
|
|
|
|
+ return $matches[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|