|
|
|
|
@@ -1,102 +1,117 @@
|
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPMailer RFC821 SMTP email transport class.
|
|
|
|
|
* Version 5.2.7
|
|
|
|
|
* PHP version 5.0.0
|
|
|
|
|
* @category PHP
|
|
|
|
|
* @package PHPMailer
|
|
|
|
|
* @link https://github.com/PHPMailer/PHPMailer/
|
|
|
|
|
* @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
|
|
|
|
|
* PHP Version 5
|
|
|
|
|
* @package PHPMailer
|
|
|
|
|
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
|
|
|
|
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
|
|
|
|
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
|
|
|
|
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
|
|
|
|
* @copyright 2013 Marcus Bointon
|
|
|
|
|
* @copyright 2004 - 2008 Andy Prevost
|
|
|
|
|
* @author Brent R. Matzelle (original founder)
|
|
|
|
|
* @copyright 2014 Marcus Bointon
|
|
|
|
|
* @copyright 2010 - 2012 Jim Jagielski
|
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
|
|
|
|
|
* @copyright 2004 - 2009 Andy Prevost
|
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
|
|
|
|
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PHPMailer RFC821 SMTP email transport class.
|
|
|
|
|
*
|
|
|
|
|
* Implements RFC 821 SMTP commands
|
|
|
|
|
* and provides some utility methods for sending mail to an SMTP server.
|
|
|
|
|
*
|
|
|
|
|
* PHP Version 5.0.0
|
|
|
|
|
*
|
|
|
|
|
* @category PHP
|
|
|
|
|
* @package PHPMailer
|
|
|
|
|
* @link https://github.com/PHPMailer/PHPMailer/blob/master/class.smtp.php
|
|
|
|
|
* @author Chris Ryan <unknown@example.com>
|
|
|
|
|
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
|
|
|
|
|
* Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
|
|
|
|
|
* @package PHPMailer
|
|
|
|
|
* @author Chris Ryan <unknown@example.com>
|
|
|
|
|
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class SMTP
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The PHPMailer SMTP Version number.
|
|
|
|
|
* The PHPMailer SMTP version number.
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
const VERSION = '5.2.7';
|
|
|
|
|
const VERSION = '5.2.8';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SMTP line break constant.
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
const CRLF = "\r\n";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The SMTP port to use if one is not specified.
|
|
|
|
|
* @type int
|
|
|
|
|
*/
|
|
|
|
|
const DEFAULT_SMTP_PORT = 25;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The maximum line length allowed by RFC 2822 section 2.1.1
|
|
|
|
|
* @type int
|
|
|
|
|
*/
|
|
|
|
|
const MAX_LINE_LENGTH = 998;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The PHPMailer SMTP Version number.
|
|
|
|
|
* @type string
|
|
|
|
|
* @deprecated This should be a constant
|
|
|
|
|
* @deprecated Use the constant instead
|
|
|
|
|
* @see SMTP::VERSION
|
|
|
|
|
*/
|
|
|
|
|
public $Version = '5.2.7';
|
|
|
|
|
public $Version = '5.2.8';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SMTP server port number.
|
|
|
|
|
* @type int
|
|
|
|
|
* @deprecated This is only ever ued as default value, so should be a constant
|
|
|
|
|
* @deprecated This is only ever used as a default value, so use the constant instead
|
|
|
|
|
* @see SMTP::DEFAULT_SMTP_PORT
|
|
|
|
|
*/
|
|
|
|
|
public $SMTP_PORT = 25;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SMTP reply line ending
|
|
|
|
|
* SMTP reply line ending.
|
|
|
|
|
* @type string
|
|
|
|
|
* @deprecated Use the class constant instead
|
|
|
|
|
* @deprecated Use the constant instead
|
|
|
|
|
* @see SMTP::CRLF
|
|
|
|
|
*/
|
|
|
|
|
public $CRLF = "\r\n";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Debug output level.
|
|
|
|
|
* Options: 0 for no output, 1 for commands, 2 for data and commands
|
|
|
|
|
* Options:
|
|
|
|
|
* * `0` No output
|
|
|
|
|
* * `1` Commands
|
|
|
|
|
* * `2` Data and commands
|
|
|
|
|
* * `3` As 2 plus connection status
|
|
|
|
|
* * `4` Low-level data output
|
|
|
|
|
* @type int
|
|
|
|
|
*/
|
|
|
|
|
public $do_debug = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The function/method to use for debugging output.
|
|
|
|
|
* Options: 'echo', 'html' or 'error_log'
|
|
|
|
|
* How to handle debug output.
|
|
|
|
|
* Options:
|
|
|
|
|
* * `echo` Output plain-text as-is, appropriate for CLI
|
|
|
|
|
* * `html` Output escaped, line breaks converted to <br>, appropriate for browser output
|
|
|
|
|
* * `error_log` Output to error log as configured in php.ini
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
public $Debugoutput = 'echo';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether to use VERP.
|
|
|
|
|
* @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
|
|
|
|
|
* @link http://www.postfix.org/VERP_README.html Info on VERP
|
|
|
|
|
* @type bool
|
|
|
|
|
*/
|
|
|
|
|
public $do_verp = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The SMTP timeout value for reads, in seconds.
|
|
|
|
|
* The timeout value for connection, in seconds.
|
|
|
|
|
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
|
|
|
|
|
* This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
|
|
|
|
|
* @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
|
|
|
|
|
* @type int
|
|
|
|
|
*/
|
|
|
|
|
public $Timeout = 15;
|
|
|
|
|
public $Timeout = 300;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The SMTP timelimit value for reads, in seconds.
|
|
|
|
|
@@ -137,7 +152,6 @@ class SMTP
|
|
|
|
|
$this->smtp_conn = 0;
|
|
|
|
|
$this->error = null;
|
|
|
|
|
$this->helo_rply = null;
|
|
|
|
|
|
|
|
|
|
$this->do_debug = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -164,15 +178,14 @@ class SMTP
|
|
|
|
|
break;
|
|
|
|
|
case 'echo':
|
|
|
|
|
default:
|
|
|
|
|
//Just echoes whatever was received
|
|
|
|
|
echo $str;
|
|
|
|
|
echo gmdate('Y-m-d H:i:s')."\t".trim($str)."\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connect to an SMTP server.
|
|
|
|
|
* @param string $host SMTP server IP or host name
|
|
|
|
|
* @param int $port The port number to connect to
|
|
|
|
|
* @param string $host SMTP server IP or host name
|
|
|
|
|
* @param int $port The port number to connect to
|
|
|
|
|
* @param int $timeout How long to wait for the connection to open
|
|
|
|
|
* @param array $options An array of options for stream_context_create()
|
|
|
|
|
* @access public
|
|
|
|
|
@@ -182,19 +195,19 @@ class SMTP
|
|
|
|
|
{
|
|
|
|
|
// Clear errors to avoid confusion
|
|
|
|
|
$this->error = null;
|
|
|
|
|
|
|
|
|
|
// Make sure we are __not__ connected
|
|
|
|
|
if ($this->connected()) {
|
|
|
|
|
// Already connected, generate error
|
|
|
|
|
$this->error = array('error' => 'Already connected to a server');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($port)) {
|
|
|
|
|
$port = self::DEFAULT_SMTP_PORT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to the SMTP server
|
|
|
|
|
if ($this->do_debug >= 3) {
|
|
|
|
|
$this->edebug('Connection: opening');
|
|
|
|
|
}
|
|
|
|
|
$errno = 0;
|
|
|
|
|
$errstr = '';
|
|
|
|
|
$socket_context = stream_context_create($options);
|
|
|
|
|
@@ -207,7 +220,6 @@ class SMTP
|
|
|
|
|
STREAM_CLIENT_CONNECT,
|
|
|
|
|
$socket_context
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Verify we connected properly
|
|
|
|
|
if (empty($this->smtp_conn)) {
|
|
|
|
|
$this->error = array(
|
|
|
|
|
@@ -217,13 +229,15 @@ class SMTP
|
|
|
|
|
);
|
|
|
|
|
if ($this->do_debug >= 1) {
|
|
|
|
|
$this->edebug(
|
|
|
|
|
'SMTP -> ERROR: ' . $this->error['error']
|
|
|
|
|
'SMTP ERROR: ' . $this->error['error']
|
|
|
|
|
. ": $errstr ($errno)"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->do_debug >= 3) {
|
|
|
|
|
$this->edebug('Connection: opened');
|
|
|
|
|
}
|
|
|
|
|
// SMTP server can take longer to respond, give longer timeout for first read
|
|
|
|
|
// Windows does not have support for this timeout function
|
|
|
|
|
if (substr(PHP_OS, 0, 3) != 'WIN') {
|
|
|
|
|
@@ -233,14 +247,11 @@ class SMTP
|
|
|
|
|
}
|
|
|
|
|
stream_set_timeout($this->smtp_conn, $timeout, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get any announcement
|
|
|
|
|
$announce = $this->get_lines();
|
|
|
|
|
|
|
|
|
|
if ($this->do_debug >= 2) {
|
|
|
|
|
$this->edebug('SMTP -> FROM SERVER:' . $announce);
|
|
|
|
|
$this->edebug('SERVER -> CLIENT: ' . $announce);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -251,7 +262,7 @@ class SMTP
|
|
|
|
|
*/
|
|
|
|
|
public function startTLS()
|
|
|
|
|
{
|
|
|
|
|
if (!$this->sendCommand("STARTTLS", "STARTTLS", 220)) {
|
|
|
|
|
if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Begin encrypted connection
|
|
|
|
|
@@ -259,8 +270,7 @@ class SMTP
|
|
|
|
|
$this->smtp_conn,
|
|
|
|
|
true,
|
|
|
|
|
STREAM_CRYPTO_METHOD_TLS_CLIENT
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
@@ -288,7 +298,6 @@ class SMTP
|
|
|
|
|
if (empty($authtype)) {
|
|
|
|
|
$authtype = 'LOGIN';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($authtype) {
|
|
|
|
|
case 'PLAIN':
|
|
|
|
|
// Start authentication
|
|
|
|
|
@@ -351,7 +360,6 @@ class SMTP
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Though 0 based, there is a white space after the 3 digit number
|
|
|
|
|
//msg2
|
|
|
|
|
$challenge = substr($this->last_reply, 3);
|
|
|
|
|
@@ -411,13 +419,13 @@ class SMTP
|
|
|
|
|
// Eliminates the need to install mhash to compute a HMAC
|
|
|
|
|
// Hacked by Lance Rushing
|
|
|
|
|
|
|
|
|
|
$b = 64; // byte length for md5
|
|
|
|
|
if (strlen($key) > $b) {
|
|
|
|
|
$bytelen = 64; // byte length for md5
|
|
|
|
|
if (strlen($key) > $bytelen) {
|
|
|
|
|
$key = pack('H*', md5($key));
|
|
|
|
|
}
|
|
|
|
|
$key = str_pad($key, $b, chr(0x00));
|
|
|
|
|
$ipad = str_pad('', $b, chr(0x36));
|
|
|
|
|
$opad = str_pad('', $b, chr(0x5c));
|
|
|
|
|
$key = str_pad($key, $bytelen, chr(0x00));
|
|
|
|
|
$ipad = str_pad('', $bytelen, chr(0x36));
|
|
|
|
|
$opad = str_pad('', $bytelen, chr(0x5c));
|
|
|
|
|
$k_ipad = $key ^ $ipad;
|
|
|
|
|
$k_opad = $key ^ $opad;
|
|
|
|
|
|
|
|
|
|
@@ -437,7 +445,7 @@ class SMTP
|
|
|
|
|
// the socket is valid but we are not connected
|
|
|
|
|
if ($this->do_debug >= 1) {
|
|
|
|
|
$this->edebug(
|
|
|
|
|
'SMTP -> NOTICE: EOF caught while checking if connected'
|
|
|
|
|
'SMTP NOTICE: EOF caught while checking if connected'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$this->close();
|
|
|
|
|
@@ -462,6 +470,9 @@ class SMTP
|
|
|
|
|
if (!empty($this->smtp_conn)) {
|
|
|
|
|
// close the connection and cleanup
|
|
|
|
|
fclose($this->smtp_conn);
|
|
|
|
|
if ($this->do_debug >= 3) {
|
|
|
|
|
$this->edebug('Connection: closed');
|
|
|
|
|
}
|
|
|
|
|
$this->smtp_conn = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -483,62 +494,52 @@ class SMTP
|
|
|
|
|
if (!$this->sendCommand('DATA', 'DATA', 354)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The server is ready to accept data!
|
|
|
|
|
* according to rfc821 we should not send more than 1000
|
|
|
|
|
* including the CRLF
|
|
|
|
|
* characters on a single line so we will break the data up
|
|
|
|
|
* into lines by \r and/or \n then if needed we will break
|
|
|
|
|
* each of those into smaller lines to fit within the limit.
|
|
|
|
|
* in addition we will be looking for lines that start with
|
|
|
|
|
* a period '.' and append and additional period '.' to that
|
|
|
|
|
* line. NOTE: this does not count towards limit.
|
|
|
|
|
* According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
|
|
|
|
|
* so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
|
|
|
|
|
* smaller lines to fit within the limit.
|
|
|
|
|
* We will also look for lines that start with a '.' and prepend an additional '.'.
|
|
|
|
|
* NOTE: this does not count towards line-length limit.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Normalize the line breaks before exploding
|
|
|
|
|
$msg_data = str_replace("\r\n", "\n", $msg_data);
|
|
|
|
|
$msg_data = str_replace("\r", "\n", $msg_data);
|
|
|
|
|
$lines = explode("\n", $msg_data);
|
|
|
|
|
// Normalize line breaks before exploding
|
|
|
|
|
$lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
|
|
|
|
|
|
|
|
|
|
/* We need to find a good way to determine if headers are
|
|
|
|
|
* in the msg_data or if it is a straight msg body
|
|
|
|
|
* currently I am assuming rfc822 definitions of msg headers
|
|
|
|
|
* and if the first field of the first line (':' separated)
|
|
|
|
|
* does not contain a space then it _should_ be a header
|
|
|
|
|
* and we can process all lines before a blank "" line as
|
|
|
|
|
* headers.
|
|
|
|
|
/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
|
|
|
|
|
* of the first line (':' separated) does not contain a space then it _should_ be a header and we will
|
|
|
|
|
* process all lines before a blank line as headers.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$field = substr($lines[0], 0, strpos($lines[0], ':'));
|
|
|
|
|
$in_headers = false;
|
|
|
|
|
if (!empty($field) && !strstr($field, ' ')) {
|
|
|
|
|
if (!empty($field) && strpos($field, ' ') === false) {
|
|
|
|
|
$in_headers = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//RFC 2822 section 2.1.1 limit
|
|
|
|
|
$max_line_length = 998;
|
|
|
|
|
|
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
|
$lines_out = null;
|
|
|
|
|
if ($line == '' && $in_headers) {
|
|
|
|
|
$lines_out = array();
|
|
|
|
|
if ($in_headers and $line == '') {
|
|
|
|
|
$in_headers = false;
|
|
|
|
|
}
|
|
|
|
|
// ok we need to break this line up into several smaller lines
|
|
|
|
|
while (strlen($line) > $max_line_length) {
|
|
|
|
|
$pos = strrpos(substr($line, 0, $max_line_length), ' ');
|
|
|
|
|
|
|
|
|
|
// Patch to fix DOS attack
|
|
|
|
|
if (!$pos) {
|
|
|
|
|
$pos = $max_line_length - 1;
|
|
|
|
|
//This is a small micro-optimisation: isset($str[$len]) is equivalent to (strlen($str) > $len)
|
|
|
|
|
while (isset($line[self::MAX_LINE_LENGTH])) {
|
|
|
|
|
//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
|
|
|
|
|
//so as to avoid breaking in the middle of a word
|
|
|
|
|
$pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
|
|
|
|
|
if (!$pos) { //Deliberately matches both false and 0
|
|
|
|
|
//No nice break found, add a hard break
|
|
|
|
|
$pos = self::MAX_LINE_LENGTH - 1;
|
|
|
|
|
$lines_out[] = substr($line, 0, $pos);
|
|
|
|
|
$line = substr($line, $pos);
|
|
|
|
|
} else {
|
|
|
|
|
//Break at the found point
|
|
|
|
|
$lines_out[] = substr($line, 0, $pos);
|
|
|
|
|
//Move along by the amount we dealt with
|
|
|
|
|
$line = substr($line, $pos + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If processing headers add a LWSP-char to the front of new line
|
|
|
|
|
* rfc822 on long msg headers
|
|
|
|
|
* RFC822 section 3.1.1
|
|
|
|
|
*/
|
|
|
|
|
if ($in_headers) {
|
|
|
|
|
$line = "\t" . $line;
|
|
|
|
|
@@ -546,12 +547,11 @@ class SMTP
|
|
|
|
|
}
|
|
|
|
|
$lines_out[] = $line;
|
|
|
|
|
|
|
|
|
|
// send the lines to the server
|
|
|
|
|
while (list(, $line_out) = @each($lines_out)) {
|
|
|
|
|
if (strlen($line_out) > 0) {
|
|
|
|
|
if (substr($line_out, 0, 1) == '.') {
|
|
|
|
|
$line_out = '.' . $line_out;
|
|
|
|
|
}
|
|
|
|
|
// Send the lines to the server
|
|
|
|
|
foreach ($lines_out as $line_out) {
|
|
|
|
|
//RFC2821 section 4.5.2
|
|
|
|
|
if (!empty($line_out) and $line_out[0] == '.') {
|
|
|
|
|
$line_out = '.' . $line_out;
|
|
|
|
|
}
|
|
|
|
|
$this->client_send($line_out . self::CRLF);
|
|
|
|
|
}
|
|
|
|
|
@@ -565,7 +565,7 @@ class SMTP
|
|
|
|
|
* Send an SMTP HELO or EHLO command.
|
|
|
|
|
* Used to identify the sending server to the receiving server.
|
|
|
|
|
* This makes sure that client and server are in a known state.
|
|
|
|
|
* Implements from RFC 821: HELO <SP> <domain> <CRLF>
|
|
|
|
|
* Implements RFC 821: HELO <SP> <domain> <CRLF>
|
|
|
|
|
* and RFC 2821 EHLO.
|
|
|
|
|
* @param string $host The host name or IP to connect to
|
|
|
|
|
* @access public
|
|
|
|
|
@@ -574,13 +574,7 @@ class SMTP
|
|
|
|
|
public function hello($host = '')
|
|
|
|
|
{
|
|
|
|
|
// Try extended hello first (RFC 2821)
|
|
|
|
|
if (!$this->sendHello('EHLO', $host)) {
|
|
|
|
|
if (!$this->sendHello('HELO', $host)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return (bool)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -588,7 +582,7 @@ class SMTP
|
|
|
|
|
* Low-level implementation used by hello()
|
|
|
|
|
* @see hello()
|
|
|
|
|
* @param string $hello The HELO string
|
|
|
|
|
* @param string $host The hostname to say we are
|
|
|
|
|
* @param string $host The hostname to say we are
|
|
|
|
|
* @access protected
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
@@ -631,28 +625,28 @@ class SMTP
|
|
|
|
|
public function quit($close_on_error = true)
|
|
|
|
|
{
|
|
|
|
|
$noerror = $this->sendCommand('QUIT', 'QUIT', 221);
|
|
|
|
|
$e = $this->error; //Save any error
|
|
|
|
|
$err = $this->error; //Save any error
|
|
|
|
|
if ($noerror or $close_on_error) {
|
|
|
|
|
$this->close();
|
|
|
|
|
$this->error = $e; //Restore any error from the quit command
|
|
|
|
|
$this->error = $err; //Restore any error from the quit command
|
|
|
|
|
}
|
|
|
|
|
return $noerror;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send an SMTP RCPT command.
|
|
|
|
|
* Sets the TO argument to $to.
|
|
|
|
|
* Sets the TO argument to $toaddr.
|
|
|
|
|
* Returns true if the recipient was accepted false if it was rejected.
|
|
|
|
|
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
|
|
|
|
|
* @param string $to The address the message is being sent to
|
|
|
|
|
* @param string $toaddr The address the message is being sent to
|
|
|
|
|
* @access public
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function recipient($to)
|
|
|
|
|
public function recipient($toaddr)
|
|
|
|
|
{
|
|
|
|
|
return $this->sendCommand(
|
|
|
|
|
'RCPT TO ',
|
|
|
|
|
'RCPT TO:<' . $to . '>',
|
|
|
|
|
'RCPT TO',
|
|
|
|
|
'RCPT TO:<' . $toaddr . '>',
|
|
|
|
|
array(250, 251)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -681,7 +675,7 @@ class SMTP
|
|
|
|
|
{
|
|
|
|
|
if (!$this->connected()) {
|
|
|
|
|
$this->error = array(
|
|
|
|
|
"error" => "Called $command without being connected"
|
|
|
|
|
'error' => "Called $command without being connected"
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -691,19 +685,19 @@ class SMTP
|
|
|
|
|
$code = substr($reply, 0, 3);
|
|
|
|
|
|
|
|
|
|
if ($this->do_debug >= 2) {
|
|
|
|
|
$this->edebug('SMTP -> FROM SERVER:' . $reply);
|
|
|
|
|
$this->edebug('SERVER -> CLIENT: ' . $reply);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!in_array($code, (array)$expect)) {
|
|
|
|
|
$this->last_reply = null;
|
|
|
|
|
$this->error = array(
|
|
|
|
|
"error" => "$command command failed",
|
|
|
|
|
"smtp_code" => $code,
|
|
|
|
|
"detail" => substr($reply, 4)
|
|
|
|
|
'error' => "$command command failed",
|
|
|
|
|
'smtp_code' => $code,
|
|
|
|
|
'detail' => substr($reply, 4)
|
|
|
|
|
);
|
|
|
|
|
if ($this->do_debug >= 1) {
|
|
|
|
|
$this->edebug(
|
|
|
|
|
'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $reply
|
|
|
|
|
'SMTP ERROR: ' . $this->error['error'] . ': ' . $reply
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
@@ -729,7 +723,7 @@ class SMTP
|
|
|
|
|
*/
|
|
|
|
|
public function sendAndMail($from)
|
|
|
|
|
{
|
|
|
|
|
return $this->sendCommand("SAML", "SAML FROM:$from", 250);
|
|
|
|
|
return $this->sendCommand('SAML', "SAML FROM:$from", 250);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -740,7 +734,7 @@ class SMTP
|
|
|
|
|
*/
|
|
|
|
|
public function verify($name)
|
|
|
|
|
{
|
|
|
|
|
return $this->sendCommand("VRFY", "VRFY $name", array(250, 251));
|
|
|
|
|
return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -751,14 +745,14 @@ class SMTP
|
|
|
|
|
*/
|
|
|
|
|
public function noop()
|
|
|
|
|
{
|
|
|
|
|
return $this->sendCommand("NOOP", "NOOP", 250);
|
|
|
|
|
return $this->sendCommand('NOOP', 'NOOP', 250);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send an SMTP TURN command.
|
|
|
|
|
* This is an optional command for SMTP that this class does not support.
|
|
|
|
|
* This method is here to make the RFC821 Definition
|
|
|
|
|
* complete for this class and __may__ be implemented in future
|
|
|
|
|
* This method is here to make the RFC821 Definition complete for this class
|
|
|
|
|
* and _may_ be implemented in future
|
|
|
|
|
* Implements from rfc 821: TURN <CRLF>
|
|
|
|
|
* @access public
|
|
|
|
|
* @return bool
|
|
|
|
|
@@ -769,7 +763,7 @@ class SMTP
|
|
|
|
|
'error' => 'The SMTP TURN command is not implemented'
|
|
|
|
|
);
|
|
|
|
|
if ($this->do_debug >= 1) {
|
|
|
|
|
$this->edebug('SMTP -> NOTICE: ' . $this->error['error']);
|
|
|
|
|
$this->edebug('SMTP NOTICE: ' . $this->error['error']);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -778,12 +772,12 @@ class SMTP
|
|
|
|
|
* Send raw data to the server.
|
|
|
|
|
* @param string $data The data to send
|
|
|
|
|
* @access public
|
|
|
|
|
* @return int|bool The number of bytes sent to the server or FALSE on error
|
|
|
|
|
* @return int|bool The number of bytes sent to the server or false on error
|
|
|
|
|
*/
|
|
|
|
|
public function client_send($data)
|
|
|
|
|
{
|
|
|
|
|
if ($this->do_debug >= 1) {
|
|
|
|
|
$this->edebug("CLIENT -> SMTP: $data");
|
|
|
|
|
$this->edebug("CLIENT -> SERVER: $data");
|
|
|
|
|
}
|
|
|
|
|
return fwrite($this->smtp_conn, $data);
|
|
|
|
|
}
|
|
|
|
|
@@ -819,12 +813,12 @@ class SMTP
|
|
|
|
|
*/
|
|
|
|
|
protected function get_lines()
|
|
|
|
|
{
|
|
|
|
|
// If the connection is bad, give up straight away
|
|
|
|
|
if (!is_resource($this->smtp_conn)) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$data = '';
|
|
|
|
|
$endtime = 0;
|
|
|
|
|
// If the connection is bad, give up now
|
|
|
|
|
if (!is_resource($this->smtp_conn)) {
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
stream_set_timeout($this->smtp_conn, $this->Timeout);
|
|
|
|
|
if ($this->Timelimit > 0) {
|
|
|
|
|
$endtime = time() + $this->Timelimit;
|
|
|
|
|
@@ -839,8 +833,8 @@ class SMTP
|
|
|
|
|
if ($this->do_debug >= 4) {
|
|
|
|
|
$this->edebug("SMTP -> get_lines(): \$data is \"$data\"");
|
|
|
|
|
}
|
|
|
|
|
// if 4th character is a space, we are done reading, break the loop
|
|
|
|
|
if (substr($str, 3, 1) == ' ') {
|
|
|
|
|
// If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
|
|
|
|
|
if ((isset($str[3]) and $str[3] == ' ')) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Timed-out? Log and break
|
|
|
|
|
@@ -854,16 +848,14 @@ class SMTP
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Now check if reads took too long
|
|
|
|
|
if ($endtime) {
|
|
|
|
|
if (time() > $endtime) {
|
|
|
|
|
if ($this->do_debug >= 4) {
|
|
|
|
|
$this->edebug(
|
|
|
|
|
'SMTP -> get_lines(): timelimit reached ('
|
|
|
|
|
. $this->Timelimit . ' sec)'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
if ($endtime and time() > $endtime) {
|
|
|
|
|
if ($this->do_debug >= 4) {
|
|
|
|
|
$this->edebug(
|
|
|
|
|
'SMTP -> get_lines(): timelimit reached ('.
|
|
|
|
|
$this->Timelimit . ' sec)'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
|