Sending Emails with Zend_Mail and Yahoo! SMTP

Posted on Updated on

When developers are trying to test emails with popular email service providers from the local server environments, it does not allow to send emails since they try to impose restrictions on spamming. Followings can be used to test email contact forms with Zend Framework and its mail function. It is tested and worked fine with yahoo SMTP settings but on zend framework. Here the trick was setting from email as same as the authenticated email address.

//values from  zend form elements
$sender = $form->getValue(‘name’);
$email = $form ->getValue(’email’);
$subject = $form ->getValue(‘subject’);
$message = $form ->getValue(‘message’);

$mail = new Zend_Mail();
$config = array(‘auth’ => ‘login’,’username’ => ‘your_e_mail@yahoo.com’,’password’ => ‘your_password’);
$transport = new Zend_Mail_Transport_Smtp(‘smtp.mail.yahoo.com’, $config);

$mail->setSubject($subject);
$mail->setFrom(‘your_e_mail@yahoo.com’, $sender); //should be the same email used for config
$mail->setReplyTo($email, $sender);
$mail->addTo(‘your_e_mail@yahoo.com ‘, ‘webmaster’);
$mail->setBodyHtml(’email body text in html’);
$mail->setBodyText(’email body text in text’);
$mail->send($transport);

——————————————————-

cheers! 🙂

Advertisements