Send email programmatically Magento 1
Send email programmatically in Magento 1
Every Magento project requires a certain level of customization. This may involve adding a new element or overriding an existing one. Today, we will talk about how to send email programmatically in Magento 1.
Magento use model to send email core/ Just load the model and set the required information.There are two types of email you can set from this mode text and html
In my case i am sending the html content in my email.
Html content
You can send a simple email using the following code.
$html="<p>Here is some content</p>";
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name'); //send the name
$mail->setToEmail('Your Email'); //Set email
$mail->setBody($html);
$mail->setSubject('Mail Subject'); //Set email subject
$mail->setFromEmail('Sender Mail Id'); //Set email from
$mail->setFromName("From Name"); //Set from name
$mail->setType('html'); // You can use Html or text as Mail format
try {
$mail->send(); //To send email
Mage::getSingleton('core/session')->addSuccess('Email Sent Successfully');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
}
?>
Moreover there is a different code if you want to send text content.Here we have just discussed the Html content.
I hope this tutorial has helped you in a simpler and easy way. For any suggestions & question, please feel free to drop a comment.
2 thoughts on “Send email programmatically Magento 1”
Leave a Reply
You must be logged in to post a comment.
great article for magento developer who want use mail funcationality
Great blog, And how can i add Bcc in this code