gpt4 book ai didi

php - 如何在 magento2 自定义电子邮件模板中添加密件抄送?

转载 作者:行者123 更新时间:2023-12-05 07:41:03 25 4
gpt4 key购买 nike

我正在使用以下代码发送邮件。邮件工作正常,但 Bcc 和 Cc 不工作。请告诉我如何设置 Bcc 和 Cc。

 class Dummy
{

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

}

提前致谢。

最佳答案

`if($custom_email){

$this->transportBuilder->addBcc($custom_email);//添加为自定义动态电子邮件地址添加 BCC

}`

这是更新后的代码:

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

关于php - 如何在 magento2 自定义电子邮件模板中添加密件抄送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45648993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com