PHP Класс ezcMailSmtpTransport

The implementation supports most of the commands specified in: - {@link http://www.faqs.org/rfcs/rfc821.html RFC821 - SMTP} - {@link http://www.faqs.org/rfcs/rfc2554.html RFC2554 - SMTP Authentication} - {@link http://www.faqs.org/rfcs/rfc2831.html RFC2831 - DIGEST-MD5 Authentication} - {@link http://www.faqs.org/rfcs/rfc2195.html RFC2195 - CRAM-MD5 Authentication} - {@link http://davenport.sourceforge.net/ntlm.html NTLM Authentication} By default, the SMTP transport tries to login anonymously to the SMTP server (if an empty username and password have been provided), or to authenticate with the strongest method supported by the server (if username and password have been provided). The default behaviour can be changed with the option preferredAuthMethod (see {@link ezcMailSmtpTransportOptions}). If the preferred method is specified via options, only that authentication method will be attempted on the SMTP server. If it fails, an exception will be thrown. Supported authentication methods (from strongest to weakest): - DIGEST-MD5 - CRAM-MD5 - NTLM (requires the PHP mcrypt extension) - XOAUTH2 - LOGIN - PLAIN Not all SMTP servers support these methods, and some SMTP servers don't support authentication at all. Example send mail: $mail = new ezcMailComposer(); $mail->from = new ezcMailAddress( '[email protected]', 'Adrian Ripburger' ); $mail->addTo( new ezcMailAddress( '[email protected]', 'Maureen Corley' ) ); $mail->subject = "This is the subject of the example mail"; $mail->plainText = "This is the body of the example mail."; $mail->build(); Create a new SMTP transport object with an SSLv3 connection. The port will be 465 by default, use the 4th argument to change it. Username and password (2nd and 3rd arguments) are left blank, which means the mail host does not need authentication. The 5th parameter is the optional $options object. $options = new ezcMailSmtpTransportOptions(); $options->connectionType = ezcMailSmtpTransport::CONNECTION_SSLV3; $transport = new ezcMailSmtpTransport( 'mailhost.example.com', '', '', null, $options ); Use the SMTP transport to send the created mail object $transport->send( $mail ); Example require NTLM authentication: Create an SMTP transport and demand NTLM authentication. Username and password must be specified, otherwise no authentication will be attempted. If NTLM authentication fails, an exception will be thrown. $options = new ezcMailSmtpTransportOptions(); $options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; $transport = new ezcMailSmtpTransport( 'mailhost.example.com', 'username', 'password', null, $options ); The option can also be specified via the option property: $transport->options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; See {@link ezcMailSmtpTransportOptions} for options you can specify for SMTP.
Наследование: implements ezcMailTransport
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$connection resource The connection to the SMTP server.
$doAuthenticate boolean This variable is set to true if a username is provided for login.
$keepConnection boolean Holds if the connection should be kept open after sending a mail.
$options ezcMailSmtpTransportOptions Holds the options of this class.
$properties array(string=>mixed) Holds the properties of this class.
$status $var int {@link STATUS_NOT_CONNECTED}, {@link STATUS_CONNECTED} or {@link STATUS_AUTHENTICATED}.

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

Метод Описание
__construct ( string $host, string $user = '', string $password = '', integer $port = null, ezcMailSmtpTransportOptions | array(string=>mixed) $options = [] ) Constructs a new ezcMailSmtpTransport.
__destruct ( ) Destructs this object.
__get ( string $name ) : mixed Returns the value of the property $name.
__isset ( string $name ) : boolean Returns true if the property $name is set, otherwise false.
__set ( string $name, mixed $value ) Sets the property $name to $value.
disconnect ( ) Sends the QUIT command to the server and breaks the connection.
getSupportedAuthMethods ( ) : array(string) Returns an array with the authentication methods supported by the SMTP transport class (not by the SMTP server!).
keepConnection ( ) Sets if the connection should be kept open after sending an email.
send ( ezcMail $mail ) Sends the ezcMail $mail using the SMTP protocol.

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

Метод Описание
auth ( $method ) : boolean Calls the appropiate authentication method based on $method.
authCramMd5 ( ) : boolean Tries to login to the SMTP server with 'AUTH CRAM-MD5' and returns true if successful.
authDigestMd5 ( ) : boolean Tries to login to the SMTP server with 'AUTH DIGEST-MD5' and returns true if successful.
authLogin ( ) : boolean Tries to login to the SMTP server with 'AUTH LOGIN' and returns true if successful.
authNtlm ( ) : boolean Tries to login to the SMTP server with 'AUTH NTLM' and returns true if successful.
authNtlmMessageType1 ( string $workstation, string $domain ) : string Generates an NTLM type 1 message.
authNtlmMessageType3 ( string $challenge, string $user, string $password, string $workstation, string $domain ) : string Generates an NTLM type 3 message from the $challenge sent by the SMTP server in an NTLM type 2 message.
authNtlmResponse ( string $challenge, string $password ) : string Calculates an NTLM response to be used in the creation of the NTLM type 3 message.
authNtlmSecurityBuffer ( string $text, integer $offset ) : string Creates an NTLM security buffer information string.
authPlain ( ) : boolean Tries to login to the SMTP server with 'AUTH PLAIN' and returns true if successful.
authXOAuth2 ( ) : boolean Tries to login to the SMTP server with 'AUTH XOAUTH2' and returns true if successful.
cmdData ( ) Sends the DATA command to the SMTP server.
cmdMail ( string $from ) Sends the MAIL FROM command, with the sender's mail address $from.
cmdRcpt ( string $email ) Sends the 'RCTP TO' to the server with the address $email.
composeSmtpMailAddress ( string $email ) Returns the $email enclosed within '< >'.
connect ( ) Creates a connection to the SMTP server and initiates the login procedure.
generateNonce ( integer $length = 32 ) : string Generates an alpha-numeric random string with the specified $length.
getData ( ) : string Returns data received from the connection stream.
getReplyCode ( &$line ) : string Returns the reply code of the last message from the server.
login ( ) Performs the initial handshake with the SMTP server and authenticates the user, if login data is provided to the constructor.
sendData ( string $data ) Sends $data to the SMTP server through the connection.
sortAuthMethods ( array $methods ) : array(string) Sorts the specified array of AUTH methods $methods by strength, so higher strength methods will be used first.
startTls ( ) : void Enables TLS on an unencrypted SMTP connection

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

__construct() публичный Метод

The constructor expects, at least, the hostname $host of the SMTP server. The username $user will be used for authentication if provided. If it is left blank no authentication will be performed. The password $password will be used for authentication if provided. Use this parameter always in combination with the $user parameter. The value $port specifies on which port to connect to $host. By default it is 25 for plain connections and 465 for TLS/SSL/SSLv2/SSLv3. Note: The ssl option from {@link ezcMailTransportOptions} doesn't apply to SMTP. If you want to connect to SMTP using TLS/SSL/SSLv2/SSLv3 use the connectionType option in {@link ezcMailSmtpTransportOptions}. For options you can specify for SMTP see {@link ezcMailSmtpTransportOptions}.
public __construct ( string $host, string $user = '', string $password = '', integer $port = null, ezcMailSmtpTransportOptions | array(string=>mixed) $options = [] )
$host string
$user string
$password string
$port integer
$options ezcMailSmtpTransportOptions | array(string=>mixed)

__destruct() публичный Метод

Closes the connection if it is still open.
public __destruct ( )

__get() публичный Метод

Returns the value of the property $name.
public __get ( string $name ) : mixed
$name string
Результат mixed

__isset() публичный Метод

Returns true if the property $name is set, otherwise false.
public __isset ( string $name ) : boolean
$name string
Результат boolean

__set() публичный Метод

Sets the property $name to $value.
public __set ( string $name, mixed $value )
$name string
$value mixed

auth() защищенный Метод

Calls the appropiate authentication method based on $method.
protected auth ( $method ) : boolean
Результат boolean

authCramMd5() защищенный Метод

Tries to login to the SMTP server with 'AUTH CRAM-MD5' and returns true if successful.
protected authCramMd5 ( ) : boolean
Результат boolean

authDigestMd5() защищенный Метод

Tries to login to the SMTP server with 'AUTH DIGEST-MD5' and returns true if successful.
protected authDigestMd5 ( ) : boolean
Результат boolean

authLogin() защищенный Метод

Tries to login to the SMTP server with 'AUTH LOGIN' and returns true if successful.
protected authLogin ( ) : boolean
Результат boolean

authNtlm() защищенный Метод

Tries to login to the SMTP server with 'AUTH NTLM' and returns true if successful.
protected authNtlm ( ) : boolean
Результат boolean

authNtlmMessageType1() защищенный Метод

Generates an NTLM type 1 message.
protected authNtlmMessageType1 ( string $workstation, string $domain ) : string
$workstation string
$domain string
Результат string

authNtlmMessageType3() защищенный Метод

Generates an NTLM type 3 message from the $challenge sent by the SMTP server in an NTLM type 2 message.
protected authNtlmMessageType3 ( string $challenge, string $user, string $password, string $workstation, string $domain ) : string
$challenge string
$user string
$password string
$workstation string
$domain string
Результат string

authNtlmResponse() защищенный Метод

Calculates an NTLM response to be used in the creation of the NTLM type 3 message.
protected authNtlmResponse ( string $challenge, string $password ) : string
$challenge string
$password string
Результат string

authNtlmSecurityBuffer() защищенный Метод

The structure of the security buffer is: - a short containing the length of the buffer content in bytes (may be zero). - a short containing the allocated space for the buffer in bytes (greater than or equal to the length; typically the same as the length). - a long containing the offset to the start of the buffer in bytes (from the beginning of the NTLM message). Example: - buffer content length: 1234 bytes (0xd204 in hexa) - allocated space: 1234 bytes( 0xd204 in hexa) - offset: 4321 bytes (0xe1100000 in hexa) then the security buffer would be 0xd204d204e1100000 (in hexa).
protected authNtlmSecurityBuffer ( string $text, integer $offset ) : string
$text string
$offset integer
Результат string

authPlain() защищенный Метод

Tries to login to the SMTP server with 'AUTH PLAIN' and returns true if successful.
protected authPlain ( ) : boolean
Результат boolean

authXOAuth2() защищенный Метод

Tries to login to the SMTP server with 'AUTH XOAUTH2' and returns true if successful.
protected authXOAuth2 ( ) : boolean
Результат boolean

cmdData() защищенный Метод

Sends the DATA command to the SMTP server.
protected cmdData ( )

cmdMail() защищенный Метод

This method must be called once to tell the server the sender address. The sender's mail address $from may be enclosed in angle brackets.
protected cmdMail ( string $from )
$from string

cmdRcpt() защищенный Метод

This method must be called once for each recipient of the mail including cc and bcc recipients. The RCPT TO commands control where the mail is actually sent. It does not affect the headers of the email. The recipient mail address $email may be enclosed in angle brackets.
protected cmdRcpt ( string $email )
$email string

composeSmtpMailAddress() защищенный Метод

If $email is already enclosed within '< >' it is returned unmodified.
protected composeSmtpMailAddress ( string $email )
$email string $return string

connect() защищенный Метод

Creates a connection to the SMTP server and initiates the login procedure.
protected connect ( )

disconnect() публичный Метод

Sends the QUIT command to the server and breaks the connection.
public disconnect ( )

generateNonce() защищенный Метод

Used in the DIGEST-MD5 authentication method.
protected generateNonce ( integer $length = 32 ) : string
$length integer
Результат string

getData() защищенный Метод

Returns data received from the connection stream.
protected getData ( ) : string
Результат string

getReplyCode() защищенный Метод

$line contains the complete data retrieved from the stream. This can be used to retrieve the error message in case of an error.
protected getReplyCode ( &$line ) : string
Результат string

getSupportedAuthMethods() публичный статический Метод

The returned array has the methods sorted by their relative strengths, so stronger methods are first in the array.
public static getSupportedAuthMethods ( ) : array(string)
Результат array(string)

keepConnection() публичный Метод

This method should be called prior to the first call to send(). Keeping the connection open is useful if you are sending a lot of mail. It removes the overhead of opening the connection after each mail is sent. Use disconnect() to close the connection if you have requested to keep it open.
public keepConnection ( )

login() защищенный Метод

Performs the initial handshake with the SMTP server and authenticates the user, if login data is provided to the constructor.
protected login ( )

send() публичный Метод

If you want to send several emails use keepConnection() to leave the connection to the server open between each mail.
public send ( ezcMail $mail )
$mail ezcMail

sendData() защищенный Метод

This method appends one line-break at the end of $data.
protected sendData ( string $data )
$data string

sortAuthMethods() защищенный Метод

For example, if the server supports: $methods = array( 'PLAIN', 'LOGIN', 'CRAM-MD5' ); then this method will return: $methods = array( 'CRAM-MD5', 'LOGIN', 'PLAIN' );
protected sortAuthMethods ( array $methods ) : array(string)
$methods array
Результат array(string)

startTls() защищенный Метод

Enables TLS on an unencrypted SMTP connection
protected startTls ( ) : void
Результат void

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

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

The connection to the SMTP server.
protected resource $connection
Результат resource

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

This variable is set to true if a username is provided for login.
protected bool $doAuthenticate
Результат boolean

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

Holds if the connection should be kept open after sending a mail.
protected bool $keepConnection
Результат boolean

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

Holds the options of this class.
protected ezcMailSmtpTransportOptions $options
Результат ezcMailSmtpTransportOptions

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

Holds the properties of this class.
protected array(string=>mixed) $properties
Результат array(string=>mixed)

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

$var int {@link STATUS_NOT_CONNECTED}, {@link STATUS_CONNECTED} or {@link STATUS_AUTHENTICATED}.
protected $status