Magento: previewing/testing transactional emails with actual data, without actually sending them?
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!
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);
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.