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])
파일 보기 프로젝트 열기: nukeviet/nukeviet

공개 프로퍼티들

프로퍼티 타입 설명
$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.

보호된 프로퍼티들

프로퍼티 타입 설명
$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