It's quite simple to send transactional emails within our custom code in magento.
Below is the code snippet to send email.
$templateId = 11; //its the transactional email template id
$senderEmail = "no-reply@senderemail.com";
$senderName = Mage::app()->getStore()->getName();
$sender = array('name' => $senderName,
'email' => $senderEmail);
$recepientEmail = Mage::getStoreConfig('trans_email/ident_sales/email');
$recepientName = Mage::getStoreConfig('trans_email/ident_sales/name');
$storeId = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('ordernum' => $refordernum);
(variables can be set on email template using var keyword e.g {{var ordernum}})
$translate = Mage::getSingleton('core/translate');
$mailTemplate = Mage::getModel('core/email_template');
Mage::getModel('core/email_template')->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
$translate->setTranslateInline(true);
if (!$mailTemplate->getSentSuccess()) {
Mage::log('Unable to submit your request. Please, try again later.');
}
Cheers!!
Below is the code snippet to send email.
$templateId = 11; //its the transactional email template id
$senderEmail = "no-reply@senderemail.com";
$senderName = Mage::app()->getStore()->getName();
$sender = array('name' => $senderName,
'email' => $senderEmail);
$recepientEmail = Mage::getStoreConfig('trans_email/ident_sales/email');
$recepientName = Mage::getStoreConfig('trans_email/ident_sales/name');
$storeId = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('ordernum' => $refordernum);
(variables can be set on email template using var keyword e.g {{var ordernum}})
$translate = Mage::getSingleton('core/translate');
$mailTemplate = Mage::getModel('core/email_template');
Mage::getModel('core/email_template')->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
$translate->setTranslateInline(true);
if (!$mailTemplate->getSentSuccess()) {
Mage::log('Unable to submit your request. Please, try again later.');
}
Cheers!!
Comments
Post a Comment