PHP Класс PHPMailer\PHPMailer\SMTP

Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
Автор: Chris Ryan
Автор: Marcus Bointon ([email protected])
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$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)

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Описание методов

authenticate() публичный метод

Must be run after hello().
См. также: 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
Результат boolean True if successfully authenticated.

client_send() публичный метод

Send raw data to the server.
public client_send ( string $data ) : integer | boolean
$data string The data to send
Результат integer | boolean The number of bytes sent to the server or false on error

close() публичный метод

Don't use this function without first trying to use QUIT.
См. также: quit()
public close ( ) : void
Результат void

connect() публичный метод

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()
Результат boolean

connected() публичный метод

Check connection state.
public connected ( ) : boolean
Результат boolean True if connected.

data() публичный метод

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
Результат boolean

edebug() защищенный метод

Output debugging info via a user-selected method.
См. также: SMTP::$Debugoutput
См. также: 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
Результат void

getDebugLevel() публичный метод

Get debug output level.
public getDebugLevel ( ) : integer
Результат integer

getDebugOutput() публичный метод

Get debug output method.
public getDebugOutput ( ) : string
Результат string

getError() публичный метод

Get the latest error.
public getError ( ) : array
Результат array

getLastReply() публичный метод

Get the last reply from the server.
public getLastReply ( ) : string
Результат string

getServerExt() публичный метод

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'
Результат mixed

getServerExtList() публичный метод

Get SMTP extensions available on the server
public getServerExtList ( ) : array | null
Результат array | null

getTimeout() публичный метод

Get SMTP timeout.
public getTimeout ( ) : integer
Результат integer

getVerp() публичный метод

Get VERP address generation mode.
public getVerp ( ) : boolean
Результат boolean

get_lines() защищенный метод

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
Результат string

hello() публичный метод

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
Результат boolean

hmac() защищенный метод

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
Результат string

mail() публичный метод

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
Результат boolean

noop() публичный метод

Used to keep keep-alives alive, doesn't actually do anything
public noop ( ) : boolean
Результат boolean

parseHelloFields() защищенный метод

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() публичный метод

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?
Результат boolean

recipient() публичный метод

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
Результат boolean

reset() публичный метод

Abort any transaction that is currently in progress. Implements rfc 821: RSET
public reset ( ) : boolean
Результат boolean True on success.

sendAndMail() публичный метод

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
Результат boolean

sendCommand() защищенный метод

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
Результат boolean True on success.

sendHello() защищенный метод

Low-level implementation used by hello()
См. также: hello()
protected sendHello ( string $hello, string $host ) : boolean
$hello string The HELO string
$host string The hostname to say we are
Результат boolean

setDebugLevel() публичный метод

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

setDebugOutput() публичный метод

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() защищенный метод

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() публичный метод

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

setVerp() публичный метод

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

startTLS() публичный метод

Initiate a TLS (encrypted) session.
public startTLS ( ) : boolean
Результат boolean

turn() публичный метод

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
Результат boolean

verify() публичный метод

Send an SMTP VRFY command.
public verify ( string $name ) : boolean
$name string The name to verify
Результат boolean

Описание свойств

$Debugoutput публичное свойство

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
Результат string | callable

$Timelimit публичное свойство

Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
public int $Timelimit
Результат integer

$Timeout публичное свойство

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
Результат integer

$do_debug публичное свойство

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
Результат integer

$do_verp публичное свойство

Whether to use VERP.
public bool $do_verp
Результат boolean

$error защищенное свойство

Error information, if any, for the last SMTP command.
protected array $error
Результат array

$helo_rply защищенное свойство

If null, no HELO string has yet been received.
protected string|null $helo_rply
Результат string | null

$last_reply защищенное свойство

The most recent reply received from the server.
protected string $last_reply
Результат string

$server_caps защищенное свойство

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
Результат array | null

$smtp_conn защищенное свойство

The socket for the server connection.
protected resource $smtp_conn
Результат resource