RSS - Latest posts Using Zend_Mail and Google SMTP to send emails

Home » 2008 » 12 » Using Zend_Mail and Google SMTP to send emails

You can set this globally, for example in your bootstrap.php file:

$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
	'auth' => 'login',
	'username' => 'YOUR_USERNAME@gmail.com',
	'password' => 'YOUR_PASSWORD',
	'ssl' => 'ssl',
	'port' => 465)
);
Zend_Mail::setDefaultTransport($tr);

And later just use the normal Zend_Mail function as usual:

$mail = new Zend_Mail();
$mail->setBodyHtml('Your html email here.');
$mail->addTo('send_to@mail.com');
$mail->setSubject('Mail Subject');
$mail->setFrom('from@mail.com');
$mail->send();

To quickly explain the settings:
You need to set the authentication type to login, and provide your Google email and password, as obviously to prevent spam Google needs some verification of who you are. Then we specify the ssl type: Zend supports tls and ssl, and for Google we need to specify the later one. This also means that we need to use port 465 instead of the standard 25.

 

You can leave a response, or trackback from your own site.

Add Comment

  1. 22nd February 2009
    at 3:30 am

    You made some good points here.

  2. Edward Savage says:
    29th April 2010
    at 2:20 pm

    Thanks for showing how to specify the port. The documentation I was reading omitted that.