How to send Email in magento

piaoling  2011-07-14 18:04:23

Any body can send mail using php mail() function.But in magento all the functionality has wriiten you need to just send argument inside those functions. See the following code to send mail using magento function

<?php
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format

try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
$this->_redirect('');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
$this->_redirect('');
}
?>

类别 :  magento(258)  |  浏览(3468)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: