Jan 24 2011

Zend Framework : Sending emails using Zend_Mail and Google Smtp

Sending emails using Zend_Mail component from Zend Framework is an easy as it can get task. On a recent project, i needed to configure Zend_Mail to work with Google Smtp server.

Here is a quick how to:

$settings = array('ssl'=>'ssl',
                                'port'=>465,
                                'auth' => 'login',
                                'username' => 'youremail@gmail.com',
                                'password' => 'YOUR_PASSWORD');
                $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $settings);
                $email_from = "YOUR_EMAIL";
                $name_from = "YOUR NAME";
                $email_to = "TO_EMAIL";
                $name_to = "TO NAME";
 
                $mail = new Zend_Mail ();
                $mail->setReplyTo($email_from, $name_from);
                $mail->setFrom ($email_from, $name_from);
                $mail->addTo ($email_to, $name_to);
                $mail->setSubject ('Testing email using google accounts and Zend_Mail');
                $mail->setBodyText ("Email body");
                $mail->send($transport);

Don’t even bother to add a different email to $email_from than your Google email, because Google will override your settings by you account email.

Update: Got a tip from Bruno Pedro, Google has smtp sending limits, you can only send up to 500 emails using a Google standard account. Read the Google answer on this limiting issue, for more info.

For a more detailed look, just check out Zend_Mail component page.

9 comments on “Zend Framework : Sending emails using Zend_Mail and Google Smtp

  1. very neat site but didnt work .. i got the error of

    No connection could be made because the target machine actively refused it.

    karthik on said:
  2. Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research about this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such excellent information being shared freely out there.

  3. This can turn into an addictive passion and is something the whole family can enjoy.

    However, you must completely do your research beforehand.

    Pinpointing shades now is easier and you will get
    the join your enemies.

  4. The best way to do this is through ensuring that you are using the official plugin – whether you’re using Word – Press or another blogging platform. The tone appeals to readers and they are more likely to trust the content and to get involved.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>