Magento: previewing/testing transactional emails with actual data, without actually sending them?
Solution 1
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!
Solution 2
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);
Solution 3
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.
Solution 4
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.
Solution 5
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
.
WackGet
Updated on June 05, 2020Comments
-
WackGet almost 4 years
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?