Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add header via Swift mailer

I am trying to add header to message sent via swift mailer.

$message = Swift_Message::newInstance($title)
          ->setFrom(array('[email protected]' => 'Name'))
          ->setTo(array($email => $email))
          ->setBody($content, 'text/html');

tried this, returns error

 $message-> addTextHeader('List-Unsubscribe', $url_unsub);

This returns does nothing, but does not return error also

$headers = $message->getHeaders();
$headers->addTextHeader('List-Unsubscribe', $url_unsub);      
$result = $mailer->send($message); 

Any idea what to do?

like image 687
Ivan Avatar asked Sep 29 '17 11:09

Ivan


1 Answers

First, change to:

$message->getHeaders()->addTextHeader('List-Unsubscribe', $url_unsub); 

because you doesn't set/relate your $headers to $message after calling getHeaders().

Second. Check if $url_unsub contains really proper format for header "List-Unsubscribe". Look e.g. here => http://www.list-unsubscribe.com/

like image 158
voodoo417 Avatar answered Sep 20 '22 16:09

voodoo417