Sunday, July 8, 2012

How to send email easily in magento?

public function sendEmail()
{
$fromEmail = "from@example.com"; // sender email address
$fromName = "John Doe"; // sender name
$toEmail = "to@example.com"; // recipient email address
$toName = "Mark Doe"; // recipient name
$body = "This is Test Email!"; // body text
$subject = "Test Subject"; // subject text
$mail = new Zend_Mail();
$mail->setBodyText($body);
$mail->setFrom($fromEmail, $fromName);
$mail->addTo($toEmail, $toName);
$mail->setSubject($subject);
try
{
$mail->send();
}
catch(Exception $ex)
{
// If you are using this code in your custom module use 'yourmodule' name.
// If not, you may keep 'customer' instead of 'yourmodule'.
Mage::getSingleton('core/session')
->addError(Mage::helper('yourmodule')
->__('Unable to send email.'));
}
}

No comments:

Post a Comment

Please mention your comments.......