magento2 发送email

定义邮件模板 (/etc/email_templates.xml)

创建邮件模板 (/view/frontend/email/hello.html)

{{template config_path="design/email/header_template"}}

Hello

{{template config_path="design/email/footer_template"}}

php代码

$templateId = 'module_hello_email_template';
$templateParams = [];

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/ @var \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder /
$transportBuilder = $objectManager->get('Magento\Framework\Mail\Template\TransportBuilder');
/ @var \Magento\Store\Model\StoreManagerInterface $storeManager /
$storeManager = $objectManager->get( 'Magento\Store\Model\StoreManagerInterface' );
/ @var \Magento\Customer\Helper\Session\CurrentCustomer $customer /
$customer = $objectManager->get( '\Magento\Customer\Helper\Session\CurrentCustomer' );

$transportBuilder->setTemplateIdentifier($templateId)
->setTemplateOptions(['area' => 'frontend', 'store' => $storeManager->getStore()->getId()])
->setTemplateVars($templateParams)
->setFrom('general') // sales,support,custom1,custom2
->addTo($customer->getCustomer()->getEmail(), $customer->getCustomer()->getFirstname())
->getTransport()
->sendMessage();

关键字:magento2

版权声明

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部