Close

February 26, 2016

Magento Debugging Transactional Emails

Magento’s transactional email templates are incredibly power tools to be able to completely customize your brand to customers. One of the toughest challenges faced by designers is being able to test the email as it would look in an inbox, using actual data. We’ve come up with a super easy way to test emails listed below.

Essentially you simply need to add this to a php script and put it in the root folder of your site, where Magento is installed. When you go to the php file directly, it will display the email directly and closely approximate how it will look in your email client.

This particular script is what we use to test with what our order emails will look like. We usually test it with a very complicated order and then a simple order, to ensure it looks okay on both sides of the spectrum.

You can easily tune the script to use whatever parameters you would set in the actual transactional email, via the emailTemplateVars array.

If you need any special customization, do not hesistate to contact us directly!

<?
date_default_timezone_set('America/New_York');
require_once('app/Mage.php');
Mage::app();
Mage::app()->setCurrentStore(1); //111113 set the store id.
 
 
$order=169694;
 
// loads the proper email template
$emailTemplate  = Mage::getModel('core/email_template')
                      ->loadByCode('CUSTOMER_NEW_ORDER_EMAIL');  //this is the transactional identifier from your transactional email in Magento Admin
 
// All variables your error log tells you that are missing can be placed like this:
 
$emailTemplateVars = array();
$emailTemplateVars['usermessage'] = "blub";
$emailTemplateVars['store'] = Mage::app()->getStore();
$emailTemplateVars['sendername'] = 'sender name';
$emailTemplateVars['receivername'] = 'receiver name';
 
// order you want to load by ID
 
$emailTemplateVars['order'] = Mage::getModel('sales/order')->load($order);
 
// load payment details:
// usually rendered by this template:
// web/app/design/frontend/base/default/template/payment/info/default.phtml
$order = $emailTemplateVars['order'];
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
                ->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore(Mage::app()->getStore()); 
 
$emailTemplateVars['payment_html'] = $paymentBlock->toHtml();
 
//displays the rendered email template
echo $emailTemplate->getProcessedTemplate($emailTemplateVars);
?>