3

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

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

}

提前致谢。

4

1 回答 1

0

`如果($custom_email){

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

}`

这是更新的代码:

$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();
于 2020-07-29T11:08:21.980 回答