php Magento:使用实际数据预览/测试交易电子邮件,而不实际发送它们?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13823911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:07:39  来源:igfitidea点击:

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

phpoopmagento

提问by WackGet

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!

我正在编辑一些包含在 Magento 交易电子邮件中的 phtml 文件,但为了测试更改,我必须实际发送电子邮件。在(例如)订单确认电子邮件的情况下,这意味着我每次要测试电子邮件时都必须下订单!

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?

有没有办法预览交易电子邮件,但让它与订单数据一起呈现?

采纳答案by WackGet

From user R.S:

来自用户 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 R.S!

这是我发现在使用模板时快速重新测试电子邮件的最接近的方法。谢谢RS!

回答by chickahoona

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

回答by MutantTurkey

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.

希望有帮助。

回答by Tom van den Heuvel

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.

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

回答by Matthias Zeis

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.

关于订单邮件,您可以在浏览器中预览它们而无需发送,您可以输入任何订单号来查看不同订单的外观。

回答by jissereitsma

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

我们实际上已经开发了一个扩展,可以让您完全做到这一点:测试从 Magento 后端发送任何 Magento 交易电子邮件。希望在这里提及它不要太商业化。:http: //www.yireo.com/software/magento-extensions/emailtester

回答by Iggy

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.

您可以进入后端,转到客户,选择您自己的客户用户,在底部您将有“发送自动生成的密码”。输入管理员密码,然后单击“保存并继续编辑”。这样您就可以将密码发送到您自己的帐户并测试您的模板。

回答by Stefan Diabo

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.

我使用一个小测试脚本再次发送订单确认电子邮件。这适用于 Magento 1.9,因为它会触发 cronjob 来处理电子邮件队列。此外,它会重置“已发送电子邮件”属性,因此 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";

回答by Rajeev Singh

Go to app/code/local/Mage/Core/Model/Email/Template.php file. In send function, around line 441 there is a piece of code

转到 app/code/local/Mage/Core/Model/Email/Template.php 文件。在发送函数中,在第 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.

它会在浏览器上回显邮件,而不会实际将其发送给用户。人们可以使用它进行测试。