Class SMTP

Description

PHPMailer RFC821 SMTP email transport class.

Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.

Located in /class.smtp.php (line 27)


	
			
Class Constant Summary
Variable Summary
string $CRLF
string|callable $Debugoutput
integer $do_debug
boolean $do_verp
array $error
string|null $helo_rply
string $last_reply
array|null $server_caps
resource $smtp_conn
integer $SMTP_PORT
integer $Timelimit
integer $Timeout
string $Version
Method Summary
bool authenticate (string $username, string $password, [string $authtype = null], [string $realm = ''], [string $workstation = ''], [null|OAuth $OAuth = null])
integer|boolean client_send (string $data)
void close ()
boolean connect (string $host, [integer $port = null], [integer $timeout = 30], [array $options = array()])
boolean connected ()
boolean data (string $msg_data)
void edebug (string $str, [integer $level = 0])
void errorHandler (integer $errno, string $errmsg)
integer getDebugLevel ()
string getDebugOutput ()
array getError ()
string getLastReply ()
bool|null|string getLastTransactionID ()
mixed getServerExt (string $name)
array|null getServerExtList ()
integer getTimeout ()
boolean getVerp ()
string get_lines ()
boolean hello ([string $host = ''])
string hmac (string $data, string $key)
boolean mail (string $from)
boolean noop ()
void parseHelloFields (string $type)
boolean quit ([boolean $close_on_error = true])
boolean recipient (string $address)
boolean reset ()
boolean sendAndMail (string $from)
boolean sendCommand (string $command, string $commandstring, integer|array $expect)
boolean sendHello (string $hello, string $host)
void setDebugLevel ([integer $level = 0])
void setDebugOutput ([string|callable $method = 'echo'])
void setError (string $message, [string $detail = ''], [string $smtp_code = ''], [string $smtp_code_ex = ''])
void setTimeout ([integer $timeout = 0])
void setVerp ([boolean $enabled = false])
boolean startTLS ()
boolean turn ()
boolean verify (string $name)
Variables
string $CRLF = "\r\n" (line 100)

SMTP reply line ending.

  • see: SMTP::CRLF
  • deprecated: Use the `CRLF` constant instead
  • access: public
string|callable $Debugoutput = 'echo' (line 127)

How to handle debug output.

Options: * `echo` Output plain-text as-is, appropriate for CLI * `html` Output escaped, line breaks converted to `
`, appropriate for browser output * `error_log` Output to error log as configured in php.ini

Alternatively, you can provide a callable expecting two params: a message string and the debug level:

  1.  $smtp->Debugoutput function($str$level{echo "debug level $level; message: $str";};

  • access: public
integer $do_debug = self::DEBUG_OFF (line 112)

Debug output level.

Options: * self::DEBUG_OFF (`0`) No debug output, default * self::DEBUG_CLIENT (`1`) Client commands * self::DEBUG_SERVER (`2`) Client commands and server responses * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages

  • access: public
boolean $do_verp = false (line 135)

Whether to use VERP.

array $error = array(
'error' => '',
'detail' => '',
'smtp_code' => '',
'smtp_code_ex' => ''
)
(line 174)

Error information, if any, for the last SMTP command.

  • access: protected
string|null $helo_rply = null (line 186)

The reply the server sent to us for HELO.

If null, no HELO string has yet been received.

  • access: protected
string $last_reply = '' (line 203)

The most recent reply received from the server.

  • access: protected
array|null $server_caps = null (line 197)

The set of SMTP extensions sent in reply to EHLO command.

Indexes of the array are extension names. Value at index 'HELO' or 'EHLO' (according to command that was sent) represents the server name. In case of HELO it is the only element of the array. Other values can be boolean TRUE or an array containing extension options. If null, no HELO/EHLO string has yet been received.

  • access: protected
resource $smtp_conn (line 168)

The socket for the server connection.

  • access: protected
integer $SMTP_PORT = 25 (line 92)

SMTP server port number.

  • see: SMTP::DEFAULT_SMTP_PORT
  • deprecated: This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
  • access: public
array $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 (.*)/'
)
(line 158)
  • var: 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.
  • access: protected
integer $Timelimit = 300 (line 151)

How long to wait for commands to complete, in seconds.

Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2

  • access: public
integer $Timeout = 300 (line 144)

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.

string $Version = '5.2.22' (line 84)

The PHPMailer SMTP Version number.

  • see: SMTP::VERSION
  • deprecated: Use the `VERSION` constant instead
  • access: public
Methods
authenticate (line 387)

Perform SMTP authentication.

Must be run after hello().

  • return: True if successfully authenticated.* @access public
  • see: SMTP::hello()
  • access: public
bool authenticate (string $username, string $password, [string $authtype = null], [string $realm = ''], [string $workstation = ''], [null|OAuth $OAuth = null])
  • string $username: The user name
  • string $password: The password
  • string $authtype: The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
  • string $realm: The auth realm for NTLM
  • string $workstation: The auth workstation for NTLM
  • null|OAuth $OAuth: An optional OAuth instance (@see PHPMailerOAuth)
client_send (line 989)

Send raw data to the server.

  • return: The number of bytes sent to the server or false on error
  • access: public
integer|boolean client_send (string $data)
  • string $data: The data to send
close (line 614)

Close the socket and clean up the state of the class.

Don't use this function without first trying to use QUIT.

void close ()
connect (line 258)

Connect to an SMTP server.

  • access: public
boolean connect (string $host, [integer $port = null], [integer $timeout = 30], [array $options = array()])
  • string $host: SMTP server IP or host name
  • integer $port: The port number to connect to
  • integer $timeout: How long to wait for the connection to open
  • array $options: An array of options for stream_context_create()
connected (line 589)

Check connection state.

  • return: True if connected.
  • access: public
boolean connected ()
data (line 639)

Send an SMTP DATA command.

Issues a data command and sends the msg_data to the server, finializing the mail transaction. $msg_data is the message that is to be send with the headers. Each header needs to be on a single line followed by a <CRLF> with the message headers and the message body being separated by and additional <CRLF>. Implements rfc 821: DATA <CRLF>

  • access: public
boolean data (string $msg_data)
  • string $msg_data: Message data to send
edebug (line 213)

Output debugging info via a user-selected method.

void edebug (string $str, [integer $level = 0])
  • string $str: Debug string to output
  • integer $level: The debug level of this message; see DEBUG_* constants
errorHandler (line 1212)

Reports an error number and string.

  • access: protected
void errorHandler (integer $errno, string $errmsg)
  • integer $errno: The error number returned by PHP.
  • string $errmsg: The error message returned by PHP.
getDebugLevel (line 1184)

Get debug output level.

  • access: public
integer getDebugLevel ()
getDebugOutput (line 1166)

Get debug output method.

  • access: public
string getDebugOutput ()
getError (line 1000)

Get the latest error.

  • access: public
array getError ()
getLastReply (line 1061)

Get the last reply from the server.

  • access: public
string getLastReply ()
getLastTransactionID (line 1233)

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.

  • access: public
bool|null|string getLastTransactionID ()
getServerExt (line 1034)

A multipurpose method

The method works in three ways, dependent on argument value and current state

  1. HELO/EHLO was not sent - returns null and set up $this->error
  2. HELO was sent $name = 'HELO': returns server name $name = 'EHLO': returns boolean false $name = any string: returns null and set up $this->error
  3. EHLO was sent $name = 'HELO'|'EHLO': returns server name $name = any string: if extension $name exists, returns boolean True or its options. Otherwise returns boolean False
In other words, one can use this method to detect 3 conditions:
  • null returned: handshake was not or we don't know about ext (refer to $this->error)
  • false returned: the requested feature exactly not exists
  • positive value returned: the requested feature exists

  • access: public
mixed getServerExt (string $name)
  • string $name: Name of SMTP extension or 'HELO'|'EHLO'
getServerExtList (line 1010)

Get SMTP extensions available on the server

  • access: public
array|null getServerExtList ()
getTimeout (line 1202)

Get SMTP timeout.

  • access: public
integer getTimeout ()
getVerp (line 1131)

Get VERP address generation mode.

  • access: public
boolean getVerp ()
get_lines (line 1075)

Read the SMTP server's response.

Either before eof or socket timeout occurs on the operation. With SMTP we can tell if we have more lines to read if the 4th character is '-' symbol. If it is a space then we don't need to read anything else.

  • access: protected
string get_lines ()
hello (line 728)

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 RFC 821: HELO <SP> <domain> <CRLF> and RFC 2821 EHLO.

  • access: public
boolean hello ([string $host = ''])
  • string $host: The host name or IP to connect to
hmac (line 557)

Calculate an MD5 HMAC hash.

Works like hash_hmac('md5', $data, $key) in case that function is not available

  • access: protected
string hmac (string $data, string $key)
  • string $data: The data to hash
  • string $key: The key to hash with
mail (line 808)

Send an SMTP MAIL command.

Starts a mail transaction from the email address specified in $from. Returns true if successful or false otherwise. If True the mail transaction is started and then one or more recipient commands may be called followed by a data command. Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>

  • access: public
boolean mail (string $from)
  • string $from: Source address of this message
noop (line 962)

Send an SMTP NOOP command.

Used to keep keep-alives alive, doesn't actually do anything

  • access: public
boolean noop ()
parseHelloFields (line 761)

Parse a reply to HELO/EHLO command to discover server extensions.

In case of HELO, the only parameter that can be discovered is a server name.

  • access: protected
void parseHelloFields (string $type)
  • string $type: - 'HELO' or 'EHLO'
quit (line 826)

Send an SMTP QUIT command.

Closes the socket if there is no error or the $close_on_error argument is true. Implements from rfc 821: QUIT <CRLF>

  • access: public
boolean quit ([boolean $close_on_error = true])
  • boolean $close_on_error: Should the connection close if an error occurs?
recipient (line 846)

Send an SMTP RCPT command.

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>

  • access: public
boolean recipient (string $address)
  • string $address: The address the message is being sent to
reset (line 862)

Send an SMTP RSET command.

Abort any transaction that is currently in progress. Implements rfc 821: RSET <CRLF>

  • return: True on success.
  • access: public
boolean reset ()
sendAndMail (line 940)

Send an SMTP SAML command.

Starts a mail transaction from the email address specified in $from. Returns true if successful or false otherwise. If True the mail transaction is started and then one or more recipient commands may be called followed by a data command. This command will send the message to the users terminal if they are logged in and send them an email. Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>

  • access: public
boolean sendAndMail (string $from)
  • string $from: The address the message is from
sendCommand (line 875)

Send a command to an SMTP server and check its return code.

  • return: True on success.
  • access: protected
boolean sendCommand (string $command, string $commandstring, integer|array $expect)
  • string $command: The command name - not sent to the server
  • string $commandstring: The actual command to send
  • integer|array $expect: One or more expected integer success codes
sendHello (line 743)

Send an SMTP HELO or EHLO command.

Low-level implementation used by hello()

boolean sendHello (string $hello, string $host)
  • string $hello: The HELO string
  • string $host: The hostname to say we are
setDebugLevel (line 1175)

Set debug output level.

  • access: public
void setDebugLevel ([integer $level = 0])
  • integer $level
setDebugOutput (line 1157)

Set debug output method.

  • access: public
void setDebugOutput ([string|callable $method = 'echo'])
  • string|callable $method: The name of the mechanism to use for debugging output, or a callable to handle it.
setError (line 1143)

Set error messages and codes.

  • access: protected
void setError (string $message, [string $detail = ''], [string $smtp_code = ''], [string $smtp_code_ex = ''])
  • string $message: The error message
  • string $detail: Further detail on the error
  • string $smtp_code: An associated SMTP error code
  • string $smtp_code_ex: Extended SMTP code
setTimeout (line 1193)

Set SMTP timeout.

  • access: public
void setTimeout ([integer $timeout = 0])
  • integer $timeout
setVerp (line 1122)

Enable or disable VERP address generation.

  • access: public
void setVerp ([boolean $enabled = false])
  • boolean $enabled
startTLS (line 348)

Initiate a TLS (encrypted) session.

  • access: public
boolean startTLS ()
turn (line 976)

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 Implements from rfc 821: TURN <CRLF>

  • access: public
boolean turn ()
verify (line 951)

Send an SMTP VRFY command.

  • access: public
boolean verify (string $name)
  • string $name: The name to verify
Class Constants
CRLF = "\r\n" (line 39)

SMTP line break constant.

DEBUG_CLIENT = 1 (line 61)

Debug level to show client -> server messages

DEBUG_CONNECTION = 3 (line 71)

Debug level to show connection status, client -> server and server -> client messages

DEBUG_LOWLEVEL = 4 (line 76)

Debug level to show all messages

DEBUG_OFF = 0 (line 56)

Debug level for no output

DEBUG_SERVER = 2 (line 66)

Debug level to show client -> server and server -> client messages

DEFAULT_SMTP_PORT = 25 (line 45)

The SMTP port to use if one is not specified.

MAX_LINE_LENGTH = 998 (line 51)

The maximum line length allowed by RFC 2822 section 2.1.1

VERSION = '5.2.22' (line 33)

The PHPMailer SMTP version number.

Documentation generated on Mon, 09 Jan 2017 11:55:21 +0000 by phpDocumentor 1.4.3