Home > Mobile >  add additional header to symfony mailer message
add additional header to symfony mailer message

Time:04-05

I don't use the Symfony Framework. When I add my header like

$mail = (new Email())
    ->from(new Address('[email protected]', 'Name'))
    ->to($recipient)
    ->subject($subject)
    ->html($body)
    ->getHeaders()
        ->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');

then a $mailer->send($mail); doesn't work anymore:-(

How do I send mail?

CodePudding user response:

getHeaders functions return an header, so in your $mail, you dont have an email but a Header

            $mail = (new Email())
                ->from(new Address('[email protected]', 'Name'))
                ->to($recipient)
                ->subject($subject)
                ->html($body);
            $headers = $mail->getHeaders();
            $headers->addHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');
            $mail->setHeaders($headers);
  • Related