Every Magento project requires a certain level of customization. This may involve adding a new element or overriding an existing one. Today, we’ll talk about how to how to send email programmatically in Magento. For any suggestions & question, please feel free to drop a comment.
Magento use model to send email core/email. Just load the model and set the required information.There are two type of email you can set from this mode text and html In my case i am sending the html content in my email. With below code you can send simple email.
<?php
$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.');
}
?>
$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.');
}
?>