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

Questions:

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?

Answers:

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!

Questions:
Answers:

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

the script looks like this:

<?php
include 'app/Mage.php';
Mage::app('default');

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

and I call it like:

php -f sendTestEmail.php -- 4303 

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

hope that helps.

Questions:
Answers:

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';
Mage::app();

// loads the proper email template
$emailTemplate  = Mage::getModel('core/email_template')
                      ->loadDefault('sales_email_order_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())
                ->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore(Mage::app()->getStore()); 

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

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

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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.:
http://www.yireo.com/software/magento-extensions/emailtester

Questions:
Answers:

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.

Questions:
Answers:

http://www.magentocommerce.com/magento-connect/send-a-test-newsletter-to-an-email.html

Good extension for test newsletter

Questions:
Answers:

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';
Mage::app('default');

$oid = '1234567';

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

$_order->sendNewOrderEmail();

// var_dump($_order);

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

echo "\nFinished\n";

Questions:
Answers:

You can use L.E.S.S to test magento email templates too. Look at below link.
http://inchoo.net/magento/magento-l-e-s-s/