PHP Class PHPMailer\PHPMailer\SMTP

Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
Author: Chris Ryan
Author: Marcus Bointon ([email protected])
Afficher le fichier Open project: nukeviet/nukeviet

Méthodes publiques

Свойство Type Description
$Debugoutput string | callable 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: $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
$Timelimit integer Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
$Timeout integer 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.
$do_debug integer 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
$do_verp boolean Whether to use VERP.

Protected Properties

Свойство Type Description
$error array Error information, if any, for the last SMTP command.
$helo_rply string | null If null, no HELO string has yet been received.
$last_reply string The most recent reply received from the server.
$server_caps array | null 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.
$smtp_conn resource The socket for the server connection.

Méthodes publiques

Méthode Description
authenticate ( string $username, string $password, string $authtype = null, OAuth $OAuth = null ) : boolean Perform SMTP authentication.
client_send ( string $data ) : integer | boolean Send raw data to the server.
close ( ) : void Close the socket and clean up the state of the class.
connect ( string $host, integer $port = null, integer $timeout = 30, array $options = [] ) : boolean Connect to an SMTP server.
connected ( ) : boolean Check connection state.
data ( string $msg_data ) : boolean Send an SMTP DATA command.
getDebugLevel ( ) : integer Get debug output level.
getDebugOutput ( ) : string Get debug output method.
getError ( ) : array Get the latest error.
getLastReply ( ) : string Get the last reply from the server.
getServerExt ( string $name ) : mixed 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
getServerExtList ( ) : array | null Get SMTP extensions available on the server
getTimeout ( ) : integer Get SMTP timeout.
getVerp ( ) : boolean Get VERP address generation mode.
hello ( string $host = '' ) : boolean Send an SMTP HELO or EHLO command.
mail ( string $from ) : boolean Send an SMTP MAIL command.
noop ( ) : boolean Send an SMTP NOOP command.
quit ( boolean $close_on_error = true ) : boolean Send an SMTP QUIT command.
recipient ( string $address ) : boolean Send an SMTP RCPT command.
reset ( ) : boolean Send an SMTP RSET command.
sendAndMail ( string $from ) : boolean Send an SMTP SAML command.
setDebugLevel ( integer $level ) Set debug output level.
setDebugOutput ( string | callable $method = 'echo' ) Set debug output method.
setTimeout ( integer $timeout ) Set SMTP timeout.
setVerp ( boolean $enabled = false ) Enable or disable VERP address generation.
startTLS ( ) : boolean Initiate a TLS (encrypted) session.
turn ( ) : boolean Send an SMTP TURN command.
verify ( string $name ) : boolean Send an SMTP VRFY command.

Méthodes protégées

Méthode Description
edebug ( string $str, integer $level ) : void Output debugging info via a user-selected method.
get_lines ( ) : string Read the SMTP server's response.
hmac ( string $data, string $key ) : string Calculate an MD5 HMAC hash.
parseHelloFields ( string $type ) Parse a reply to HELO/EHLO command to discover server extensions.
sendCommand ( string $command, string $commandstring, integer | array $expect ) : boolean Send a command to an SMTP server and check its return code.
sendHello ( string $hello, string $host ) : boolean Send an SMTP HELO or EHLO command.
setError ( string $message, string $detail = '', string $smtp_code = '', string $smtp_code_ex = '' ) Set error messages and codes.

Method Details

authenticate() public méthode

Must be run after hello().
See also: hello()
public authenticate ( string $username, string $password, string $authtype = null, OAuth $OAuth = null ) : boolean
$username string The user name
$password string The password
$authtype string The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
$OAuth OAuth An optional OAuth instance for XOAUTH2 authentication
Résultat boolean True if successfully authenticated.

client_send() public méthode

Send raw data to the server.
public client_send ( string $data ) : integer | boolean
$data string The data to send
Résultat integer | boolean The number of bytes sent to the server or false on error

close() public méthode

Don't use this function without first trying to use QUIT.
See also: quit()
public close ( ) : void
Résultat void

connect() public méthode

Connect to an SMTP server.
public connect ( string $host, integer $port = null, integer $timeout = 30, array $options = [] ) : boolean
$host string SMTP server IP or host name
$port integer The port number to connect to
$timeout integer How long to wait for the connection to open
$options array An array of options for stream_context_create()
Résultat boolean

connected() public méthode

Check connection state.
public connected ( ) : boolean
Résultat boolean True if connected.

data() public méthode

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 with the message headers and the message body being separated by and additional . Implements rfc 821: DATA
public data ( string $msg_data ) : boolean
$msg_data string Message data to send
Résultat boolean

edebug() protected méthode

Output debugging info via a user-selected method.
See also: SMTP::$Debugoutput
See also: SMTP::$do_debug
protected edebug ( string $str, integer $level ) : void
$str string Debug string to output
$level integer The debug level of this message; see DEBUG_* constants
Résultat void

getDebugLevel() public méthode

Get debug output level.
public getDebugLevel ( ) : integer
Résultat integer

getDebugOutput() public méthode

Get debug output method.
public getDebugOutput ( ) : string
Résultat string

getError() public méthode

Get the latest error.
public getError ( ) : array
Résultat array

getLastReply() public méthode

Get the last reply from the server.
public getLastReply ( ) : string
Résultat string

getServerExt() public méthode

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
public getServerExt ( string $name ) : mixed
$name string Name of SMTP extension or 'HELO'|'EHLO'
Résultat mixed

getServerExtList() public méthode

Get SMTP extensions available on the server
public getServerExtList ( ) : array | null
Résultat array | null

getTimeout() public méthode

Get SMTP timeout.
public getTimeout ( ) : integer
Résultat integer

getVerp() public méthode

Get VERP address generation mode.
public getVerp ( ) : boolean
Résultat boolean

get_lines() protected méthode

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.
protected get_lines ( ) : string
Résultat string

hello() public méthode

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 and RFC 2821 EHLO.
public hello ( string $host = '' ) : boolean
$host string The host name or IP to connect to
Résultat boolean

hmac() protected méthode

Works like hash_hmac('md5', $data, $key) in case that function is not available
protected hmac ( string $data, string $key ) : string
$data string The data to hash
$key string The key to hash with
Résultat string

mail() public méthode

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 FROM:
public mail ( string $from ) : boolean
$from string Source address of this message
Résultat boolean

noop() public méthode

Used to keep keep-alives alive, doesn't actually do anything
public noop ( ) : boolean
Résultat boolean

parseHelloFields() protected méthode

In case of HELO, the only parameter that can be discovered is a server name.
protected parseHelloFields ( string $type )
$type string - 'HELO' or 'EHLO'

quit() public méthode

Closes the socket if there is no error or the $close_on_error argument is true. Implements from rfc 821: QUIT
public quit ( boolean $close_on_error = true ) : boolean
$close_on_error boolean Should the connection close if an error occurs?
Résultat boolean

recipient() public méthode

Sets the TO argument to $toaddr. Returns true if the recipient was accepted false if it was rejected. Implements from rfc 821: RCPT TO:
public recipient ( string $address ) : boolean
$address string The address the message is being sent to
Résultat boolean

reset() public méthode

Abort any transaction that is currently in progress. Implements rfc 821: RSET
public reset ( ) : boolean
Résultat boolean True on success.

sendAndMail() public méthode

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 FROM:
public sendAndMail ( string $from ) : boolean
$from string The address the message is from
Résultat boolean

sendCommand() protected méthode

Send a command to an SMTP server and check its return code.
protected sendCommand ( string $command, string $commandstring, integer | array $expect ) : boolean
$command string The command name - not sent to the server
$commandstring string The actual command to send
$expect integer | array One or more expected integer success codes
Résultat boolean True on success.

sendHello() protected méthode

Low-level implementation used by hello()
See also: hello()
protected sendHello ( string $hello, string $host ) : boolean
$hello string The HELO string
$host string The hostname to say we are
Résultat boolean

setDebugLevel() public méthode

Set debug output level.
public setDebugLevel ( integer $level )
$level integer

setDebugOutput() public méthode

Set debug output method.
public setDebugOutput ( string | callable $method = 'echo' )
$method string | callable The name of the mechanism to use for debugging output, or a callable to handle it.

setError() protected méthode

Set error messages and codes.
protected setError ( string $message, string $detail = '', string $smtp_code = '', string $smtp_code_ex = '' )
$message string The error message
$detail string Further detail on the error
$smtp_code string An associated SMTP error code
$smtp_code_ex string Extended SMTP code

setTimeout() public méthode

Set SMTP timeout.
public setTimeout ( integer $timeout )
$timeout integer

setVerp() public méthode

Enable or disable VERP address generation.
public setVerp ( boolean $enabled = false )
$enabled boolean

startTLS() public méthode

Initiate a TLS (encrypted) session.
public startTLS ( ) : boolean
Résultat boolean

turn() public méthode

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
public turn ( ) : boolean
Résultat boolean

verify() public méthode

Send an SMTP VRFY command.
public verify ( string $name ) : boolean
$name string The name to verify
Résultat boolean

Property Details

$Debugoutput public_oe property

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: $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
public string|callable $Debugoutput
Résultat string | callable

$Timelimit public_oe property

Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
public int $Timelimit
Résultat integer

$Timeout public_oe property

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.
public int $Timeout
Résultat integer

$do_debug public_oe property

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
public int $do_debug
Résultat integer

$do_verp public_oe property

Whether to use VERP.
public bool $do_verp
Résultat boolean

$error protected_oe property

Error information, if any, for the last SMTP command.
protected array $error
Résultat array

$helo_rply protected_oe property

If null, no HELO string has yet been received.
protected string|null $helo_rply
Résultat string | null

$last_reply protected_oe property

The most recent reply received from the server.
protected string $last_reply
Résultat string

$server_caps protected_oe property

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.
protected array|null $server_caps
Résultat array | null

$smtp_conn protected_oe property

The socket for the server connection.
protected resource $smtp_conn
Résultat resource