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( 'sender@example.com', 'Adrian Ripburger' );
$mail->addTo( new ezcMailAddress( 'receiver@example.com', '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.