Ivan
Ivan

Reputation: 191

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?

Upvotes: 6

Views: 5320

Answers (1)

voodoo417
voodoo417

Reputation: 12091

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/

Upvotes: 6

Related Questions