Magento: Send Transactional Email

In Magento, Transactional Email Templates can be created from System -> Transactional Emails. This article shows

how we can send transactional emails programmatically.

There are few necessary things for any transactional email in Magento. They are:-

Template ID = ID of your transactional email template

Sender Name

Sender Email

Recepient Name

Recepient Email

Store ID = Current user’s store ID

Vars = Variables to use in transactional email template

Add a new template from System -> Transactional Emails and then you will see the ID of your template. That is your

Template ID to be used in code below.

You can write Sender Name, Sender Email, Recepient Name, and Recepient Email manually or you can the name and email from Store Email

Addresses (System -> Configuration -> GENERAL -> Store Email Addresses).

Store Email Addresses

In the code below, Sender Name and Email is taken from Store Config and Recepient Name and Email is written manually.

Looking for improvement for your Magento Store?
Facebook Connector Extension
Product related article extension
Magento Offer popup on exit extension
Unlimited Slideshow Magento Extension
Light Checkout in One Step Magento Extension

Custom variables for transactional email templates can be used with curly brackets like:-

{{var myVariableName}}

New email template

Here is the full code to send transactional email in Magento:-

public function sendTransactionalEmail()
	// Transactional Email Template's ID
	$templateId = 1;

	// Set sender information
	$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
	$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
	$sender = array('name' => $senderName,
		        'email' => $senderEmail);

	// Set recepient information
	$recepientEmail = '[email protected]';
	$recepientName = 'John Doe';		

	// Get Store ID
	$store = Mage::app()->getStore()->getId();

	// Set variables that can be used in email template
	$vars = array('customerName' => '[email protected]',
		      'customerEmail' => 'Mr. Nil Cust');

	$translate  = Mage::getSingleton('core/translate');

	// Send Transactional Email
		->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);


Hope this helps. Thanks.

Leave a Reply

Your email address will not be published.

2 + 1 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>