Home » Php » Magento: previewing/testing transactional emails with actual data, without actually sending them?

Magento: previewing/testing transactional emails with actual data, without actually sending them?

Posted by: admin November 29, 2017 Leave a comment


I’m editing some phtml files which are included in transactional emails in Magento, but in order to test the changes, I have to actually send the emails. In the case of (e.g.) the order confirmation email this means I have to place an order each time I want to test an email!

Choosing “preview email” in the backend does not help because the email contains no visible order data.

Is there a way to preview a transactional email but have it render with order data?


From user R.S:

You dont have to create a new order, you could resend a previous order email (by going to that order and click resend email).

That’s the closest thing I’ve found to quickly re-test emails when playing around with the templates. Thanks R.S!


For sales orders, I use a test account and a script I have in my root directory.

the script looks like this:

include 'app/Mage.php';

$_order = Mage::getModel('sales/order')->load($argv[1]);

and I call it like:

php -f sendTestEmail.php -- 4303 

where 4303 is the order I have used for testing before.

hope that helps.


The following snippet will render the “new sales order” email and displays it for any given order. Put the following in /test.php for example and just browse to the proper location like http://www.example.com/test.php

require_once 'app/Mage.php';

// loads the proper email template
$emailTemplate  = Mage::getModel('core/email_template')

// 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(673);

// 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())

$emailTemplateVars['payment_html'] = $paymentBlock->toHtml();

//displays the rendered email template
echo $emailTemplate->getProcessedTemplate($emailTemplateVars);


Follow the instructions in this blogpost: Magento (L)ocalhost (E)mail (S)erver (S)imulator (Nov 2010; by Branko Ajzele)
Magento will save the html e-mails, including all the variables you’re trying to send in var/log.


We developed a free open-source extension called Hackathon_EmailPreview.

Concerning order mails you can preview them in the browser without sending and you can enter any order number to check what different orders would look like.


We have actually developed an extension that allows you to do exactly this: Test send any Magento transactional email from within the Magento backend. Hope it’s not too commercial to mention it here.:


You can enter backend, go to customers, select your own customer user, and at the bottom you will have “Send Auto-Generated Password”. Insert admin password and click “Save and continue editing”. This way you will send a password to your own account and test your template.



Good extension for test newsletter


I use a little test script to send the order confirmation email again. This works with Magento 1.9 because it triggers the cronjob to process the email queue. Further it resets the attribute “Email sent” so Magento does not skip sending that email.

include 'app/Mage.php';

$oid = '1234567';

$_order = Mage::getModel('sales/order')->load($oid);    


// var_dump($_order);

// Trigger email queue
$a = new Mage_Core_Model_Email_Queue();

echo "\nFinished\n";


You can use L.E.S.S to test magento email templates too. Look at below link.