How to add custom header to zend Mail\Message

527 Views Asked by At

I am using Zend\Mail\Message to send an emails.Need to add some custom headers to mail but Mail\Message don't have addHeader() function.I am using Zend Framework 2.Is there any other function which can be used to add custom headers to mails.I had referred link in documentation.But I can not find addHeader in Mail\Message. zend-mail version is 2.10.0

2

There are 2 best solutions below

0
Greco Jonathan On

According to the documentation you should consider to use the headers like this :

$message->getHeaders()->addHeaderLine('X-API-Key', 'FOO-BAR-BAZ-BAT');

Full documentation is found here

0
Yogesh On

Issue with following is it append <=?UTF-8?Q?$header?=>: to value $this->getHeaders()->addHeader($header) but I was needing plain headers.

I had created Custom class which extends the \Zend\Mail\Header\HeaderInterface And overwrite public static function fromString function. Passed the header as follows

$customHeader = CustomHeaderClass::fromString($header);
$this->getHeaders()->addHeader($customHeader);