添加额外的 header 到 symfony 邮件程序消息

add additional header to symfony mailer message

我不使用 Symfony 框架。当我添加 header 喜欢

$mail = (new Email())
    ->from(new Address('info@example.com', 'Name'))
    ->to($recipient)
    ->subject($subject)
    ->html($body)
    ->getHeaders()
        ->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');

然后 $mailer->send($mail); 不再起作用了:-(

如何发送邮件?

getHeaders 函数 return 和 header,因此在您的 $mail 中,您没有电子邮件,而是 Header

            $mail = (new Email())
                ->from(new Address('info@example.com', 'Name'))
                ->to($recipient)
                ->subject($subject)
                ->html($body);
            $headers = $mail->getHeaders();
            $headers->addHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');
            $mail->setHeaders($headers);