Tutorialsplane

Magento send transactional email programmatically


Magento send transactional email programmatically: In Magento, we know emails are automatically sent on certain actions such as order creation, invoice generation etc. Each email has a template which is used in that email. You can find the template in admin under the tag – System->Transaction Email where you can manage them. We sometimes need to send transactional email in another module programmatically. Here in this tutorial, we are going to explain how you can send transactional emails.


For Magento 2.x Email Sending Click Here

Magento send transactional email programmatically

Here in this example we assume that you have created an email template. So in this example we will use template id ie. 10 . Here is an example –

Magento send transactional email programmatically:

<?php $templateId = 10;
$senderName = 'John Dee';
$senderEmail = 'johndee@example.com';
$sender = array('name' =?> $senderName,'email' => $senderEmail);
//recepient
$email = "customer@example.com";
$name = "Kelly";

// Set variables that can be used in email template
$variables = array('custom_var' => $yourCustomVariable);

$translate = Mage::getSingleton('core/translate');
$storeId = Mage::app()->getStore()->getId();
// Now Send Transactional Email
try{
Mage::getModel('core/email_template')->sendTransactional($templateId, $sender, $email, $name, $variables , $storeId);
}
catch(Exception $e){
 echo $e->getMessage();
}
?>

$variables = array(‘custom_var’ => $yourCustomVariable); You use this to pass the custom variables to your email template if you want in template. Using the above example you can send the transactional email easily.