$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.
Datei anzeigen
Open project: zetacomponents/mail
Class Usage Examples
Property | Type | Description | |
---|---|---|---|
$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}. |
Method | Description | |
---|---|---|
__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. |
Method | Description | |
---|---|---|
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 |
protected authCramMd5 ( ) : boolean | ||
return | boolean |
protected authDigestMd5 ( ) : boolean | ||
return | boolean |
protected authXOAuth2 ( ) : boolean | ||
return | boolean |
protected composeSmtpMailAddress ( string $email ) | ||
string | $return string |
protected connect ( ) |
public disconnect ( ) |
protected generateNonce ( integer $length = 32 ) : string | ||
$length | integer | |
return | string |
protected getReplyCode ( &$line ) : string | ||
return | string |
public static getSupportedAuthMethods ( ) : array(string) | ||
return | array(string) |
public keepConnection ( ) |
protected login ( ) |
public send ( ezcMail $mail ) | ||
ezcMail |
$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 | |
return | array(string) |
protected resource $connection | ||
return | resource |
protected bool $doAuthenticate | ||
return | boolean |
protected bool $keepConnection | ||
return | boolean |
protected ezcMailSmtpTransportOptions $options | ||
return | ezcMailSmtpTransportOptions |
protected array(string=>mixed) $properties | ||
return | array(string=>mixed) |