24
Jan

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.

Related posts:

  1. Zend Framework: How-to interact with Google Calendar (Part 1/2)
  2. Starting with Zend Framework – Configuration File and Database Connection
  3. 4 Tips for getting your productivity back
  4. Google Apps Next Language War – Ruby, Perl, Java and Php on the lead
  5. Zend Framework : Consuming feeds using Zend_Feed

enjoyed this post? share with others:

twitter stumble upon digg

This entry was posted on Monday, January 24th, 2011 at 9:13 pm and is filed under Coding, php. You can follow any responses to this entry through the RSS 2.0 feed.

comments

1
  1. June 17th, 2011 | 时间当铺 says:

    thank you very much!

    i do it follow you,but it doesn’t work.

leave a comment