Answers:
好的调试功能会有所帮助,
在Magento2中发送交易电子邮件
class Dummy
{
/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
private $_transportBuilder;
public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder){
$this->_transportBuilder = $transportBuilder;
}
public function sendEmail($templateId =1, $storeId =1,$templateParams)
{
$transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
->setTemplateVars($templateParams)
->setFrom('someemail@email.com')
->addTo('toemail@email.com')
->setReplyTo('replyto@email.com')
->addBcc('bcc@email.com')
->getTransport();
$transport->sendMessage();
}
}
<!--@subject Promopoup@-->
Magento 2使用\ Magento \ Framework \ Mail \ Template \ TransportBuilder类发送自定义电子邮件。
您需要创建一个简单的模块并设置email_tempaltes.xml文件以定义您的交易邮件模板。
您可以从Adminhtml或“前端作用域”区域发送邮件。
我共享了一个逐步指南的链接,该指南使用模块从Magento 2发送自定义邮件。
它为我工作
$emailTemplateVariables = array();
$emailTempVariables['myvar'] = $myvar;
$senderName = 'test';
$senderEmail = 'sender@test.com';
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($emailTempVariables);
$sender = [
'name' => $senderName,
'email' => $senderEmail,
];
$transport = $this->_transportBuilder->setTemplateIdentifier('myemail_email_template')
->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
->setTemplateVars(['data' => $postObject])
->setFrom($sender)
->addTo($email)
->setReplyTo($senderEmail)
->getTransport();
$transport->sendMessage();
更多信息