Tag Archives: Gmail

Zend_Mail with GMail

Zend_Mail and GMail
You know how to setup Zend_Mail with SMTP, but you don’t know how to set it up with GMail! Here’s how to do it. Just follow the instructions 😉

$mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
    'auth'     => 'login',
    'username' => 'xxxxxx@gmail.com',
    'password' => 'passxxxxx',
    'port'     => '587',
    'ssl'      => 'tls',

Send Mail with Zend Framework

Simple, but Doesn’t Work!

It may sound strange, because all this is quite well documented in the Zend Framework documentation. Indeed it’s very very simple and all is done only by few lines of code.

$mail = new Zend_Mail();
$mail->setBodyHtml('some message - it may be html formatted text');
$mail->addTo('recipient@example.com', 'recipient');

Even it look simple though, it may not work on your localhost while you’re trying to make it work! Because you’ve to have sendmail setup. And in Zend Framework sendmail is the default transport protocol for sending mails.

What You Have to Do to Make it Work?

Actually you’ve simply to add a transport protocol, just like that:

$tr = new Zend_Mail_Transport_Smtp('smtp.example.com',
                    array('auth' => 'login',
                             'username' => 'username',
                             'password' => 'password'));

Where Did I Get These?

Well look at your favorite mail account you probably use every day. It may be hosted in GMail or wherever, but there are some configurations you have to port under Zend’s code and everything will be just fine until you develop the app!