Sending email using gmail’s smtp with Zend Framework

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.

Update: There’s a daily limit of outgoing emails you can send using this smtp, I experienced a problem of maxing my limit while sending out confirmation emails to the users of my facebook app. So if you are looking to do the same, just be warned that its a bad idea.

$config = array(
‘ssl’ => ‘tls’,
‘port’ => 587,
‘auth’ => ‘login’,
‘username’ => ‘’,
‘password’ => ‘password’);

$transport = new Zend_Mail_Transport_Smtp(‘’, $config);
//Use this if you do not want to specify $transport evertime you use Zend_Mail->send()

$mail = new Zend_Mail();
$mail->setBodyText(‘Email body in plain text’);
$mail->setBodyHtml(‘Email body in HTML’);
$mail->setFrom(‘’, ‘Name of sender’);
$mail->setReplyTo(‘’,’Name of sender’);
$mail->addTo(‘’, ‘Name of recipient’ );
$mail->setSubject(‘Your trial at FItness First’);

You can use your own domain name using gmail’s coporate email service, if not, just use for the domain.

Catch, gmail automatically replaces whatever ‘from’ or ‘reply-to’ you have specified with the account you are authenticating with ( To use another account, you must allow gmail to send using that email address by following the steps here.

8 thoughts on “Sending email using gmail’s smtp with Zend Framework

    1. ryan

      Hey emeraldjava, not sure if this is the most efficient way, but this is what I do usually: 1. Define the params in my application.ini, 2. load the params in bootlstrap, the params from Zend_Registry where I need them.

      In application.ini:

      ; SMTP configuration
      smtpConfig.ssl = "tls"
      smtpConfig.port = "587"
      smtpConfig.auth = "login"
      smtpConfig.username = ""
      smtpConfig.password = "password"

      Load it in my bootstrap:

      protected function _initConfig(){

      $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',APPLICATION_ENV);

      $registry = Zend_Registry::getInstance();
      $registry->set('config', $config);
      $registry->set('smtpConfig', $config->smtpConfig);


      return $config;

      Then access it else where by getting it from Zend_Registry

      $smtpConfig = Zend_Registry::get('smtpConfig');


Leave a Reply

Your email address will not be published. Required fields are marked *