简体   繁体   English

Magento:预览/测试具有实际数据的交易电子邮件,而不实际发送它们吗?

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

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. 我正在编辑Magento的事务电子邮件中包含的一些phtml文件,但是为了测试更改,我必须实际发送电子邮件。 In the case of (eg) 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 RS: 从用户RS:

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 RS! 谢谢RS!

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 例如,将以下内容放在/test.php中,然后浏览至正确的位置,例如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. 其中4303是我之前用于测试的顺序。

hope that helps. 希望能有所帮助。

请按照此博客文章中的说明进行操作: Magento(L)ocalhost(E)mail(S)erver(S)imulator(2010年11月; Branko Ajzele撰写) Magento将保存html电子邮件,包括您要尝试的所有变量。发送var/log

We have actually developed an extension that allows you to do exactly this: Test send any Magento transactional email from within the Magento backend. 实际上,我们已经开发了一个扩展,使您可以执行以下操作:测试从Magento后端发送任何Magento事务电子邮件。 Hope it's not too commercial to mention it here.: http://www.yireo.com/software/magento-extensions/emailtester 希望在这里提及它不是太商业。: http : //www.yireo.com/software/magento-extensions/emailtester

We developed a free open-source extension called Hackathon_EmailPreview . 我们开发了一个名为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. 关于订单邮件,您可以在浏览器中预览它们而无需发送,也可以输入任何订单号以检查不同的订单。

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. 这样,您将向自己的帐户发送密码并测试您的模板。

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. 这适用于Magento 1.9,因为它会触发cronjob处理电子邮件队列。 Further it resets the attribute "Email sent" so Magento does not skip sending that email. 此外,它会重置属性“已发送电子邮件”,因此Magento不会跳过发送该电子邮件。

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";

Go to app/code/local/Mage/Core/Model/Email/Template.php file. 转到app / code / local / Mage / Core / Model / Email / Template.php文件。 In send function, around line 441 there is a piece of code 在发送功能中,第441行周围有一段代码

   if ($this->isPlain()) {
         $mail->setBodyText($text);
    } else {
        $mail->setBodyHTML($text);
    }
  echo $text;die();

it will echo the mail on the browser without actually sending it to the user. 它会在浏览器中回显邮件,而无需实际将其发送给用户。 One can used this for testing. 可以将其用于测试。

I have released an extension allowing you to preview transactional mails from your back-office. 我发布了一个扩展程序,使您可以预览后台的交易邮件。 You just have to pass one order, and then a mail preview button will be available on it in the BO. 您只需要传递一个订单,然后BO中就可以使用邮件预览按钮。 Additionally, it allows you to enables template/block hints directly in the mail preview window. 此外,它允许您直接在邮件预览窗口中启用模板/阻止提示。

See it here : https://github.com/OddBrew/Oddbrew_MailViewer 在这里查看: https : //github.com/OddBrew/Oddbrew_MailViewer

This is a free extension, so I hope it does not fall under the promotional rules of SO. 这是一个免费的扩展程序,所以我希望它不属于SO的促销规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM