Custom Email Templates in Magento


I am explaining here the method for sending custom emails using the custom email templates with variables.

1) Create an email template from Admin-end > System > Transactional Emails, for example lets put this as Template Content

"htmlescape var=$":"Customer Name",
"var":"Customer Email"
Dear {{htmlescape var=$}},<br/>        
Your E-mail</strong>: {{var}}

2) Suppose the id of the template created is 3

3) Below code you can write in any view file (.phtml) or in any model or controller (.php) file

				$customer = Mage::getModel('customer/customer')->load(2); //suppose the customer whose data to be fetched is 2
               		$mailTemplate = Mage::getModel('core/email_template');
        			/* @var $mailTemplate Mage_Core_Model_Email_Template */
        			$translate  = Mage::getSingleton('core/translate');
               		$templateId = 3; //template for sending customer data
               		$template_collection =  $mailTemplate->load($templateId);     		            		
					$template_data = $template_collection->getData();
       					$templateId = $template_data['template_id'];
       					$mailSubject = $template_data['template_subject'];      					
       					//fetch sender data from Adminend > System > Configuration > Store Email Addresses > General Contact
                 		$from_email = Mage::getStoreConfig('trans_email/ident_general/email'); //fetch sender email
						$from_name = Mage::getStoreConfig('trans_email/ident_general/name'); //fetch sender name
       					$sender = array('name'  => $from_name,
                  						'email' => $from_email);                  				
						$vars = array('customer'=>$customer); //for replacing the variables in email with data					
						/*This is optional*/
					  	$storeId = Mage::app()->getStore()->getId();
					  	$model = $mailTemplate->setReplyTo($sender['email'])->setTemplateSubject($mailSubject);
					  	$email = $customer->getEmail();
					  	$name = $customer->getName();				    				   		
       		   			$model->sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);				  		
	  	 				if (!$mailTemplate->getSentSuccess()) {
			                    throw new Exception();

Hope this is helpful.

9 Responses to “Custom Email Templates in Magento”

  1. garry says:

    Working on the magento is not a big task and addition of emails templates increase the user interaction more.

  2. John says:

    If you need to add product into email template you may try this extension:

  3. L says:

    Hi, I need your help with this please: I edited my email templates on Magento but don’t remember deleting the existing ones. Can you please help me with pointers as to where I can find them please?

    Thank you.

  4. Dion says:


    I wonder if can help with a Magento question?

    Do you know how to add an image of the product to the order email template and a product link back to its product page on the Magento site? I can’t find any info on this, not sure if can be done, any help would be great.



Leave a Reply to garry