Zend Framework - Gmail SMTP Authentication
Zend_Mail supports the use of SMTP authentication, which can be enabled be passing the 'auth' parameter to the configuration array in the Zend_Mail_Transport_Smtp constructor. The available built-in authentication methods are PLAIN, LOGIN and CRAM-MD5 which all expect a 'username' and 'password' value in the configuration array.
To send emails using gmail’s smtp server, you must specify the tls port by providing the ‘ssl’ and ‘port’ in the config array. The default port for tls is 25 but gmail is using 587. You will also need to authenticate with your account and password.
Example #1 Enabling authentication within Zend_Mail_Transport_Smtp
$config = array(
‘ssl’ => ‘tls’,
‘port’ => 587,
‘auth’ => ‘login’,
‘username’ => ‘email@example.com’,
‘password’ => ‘password’);
$transport = new Zend_Mail_Transport_Smtp(‘smtp.gmail.com’, $config);
$mail = new Zend_Mail();
$mail -> setBodyText('This is the text of the mail.');
$mail -> setFrom('firstname.lastname@example.org', 'Some Sender');
$mail -> addTo('email@example.com', 'Some Recipient');
$mail -> setSubject('TestSubject');
$mail -> send($transport);
You can use your own domain name using gmail’s coporate email service, if not, just use gmail.com for the domain.
Catch, gmail automatically replaces whatever ‘from’ or ‘reply-to’ you have specified with the account you are authenticating with (firstname.lastname@example.org).
Note: Authentication types
The authentication type is case-insensitive but has no punctuation. E.g. to use CRAM-MD5 you would pass 'auth' => 'crammd5' in the Zend_Mail_Transport_Smtp constructor.