Looking for some help in adding a custom header.
I need to add a custom header similar to v3.3.3 using:
$message->headers->set("name", "value");
and can not find the proper method.
Thanks
Kevin
How to add a custom header - Using 4.0.0-b5
Moderators: Chris Corbyn, General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: How to add a custom header - Using 4.0.0-b5
This is one area that changed drastically. The whole model on which headers are based had to be re-thought out if things were to comply with RFC 2822 (and others) in a nice abstract way.
Note that there are other "types" of header you can add such as these:
And...
There are more available methods that I'm working on documentation for.
Code: Select all
$message->getHeaders()->addTextHeader('Name-Of-Header', 'value of header');
/* Results...
Name-Of-Header: value of header
*/
Code: Select all
$message->getHeaders()->addMailboxHeader('Header-Name', array(
'address1@domain.tld' => 'Person One',
'address2@domain.tld' => 'Person Two'
));
/* Results...
Header-Name: Person One <address1@domain.tld>, Person Two <address2@domain.tld>
*/Code: Select all
$message->addDateHeader('X-Some-Date', time());
/* Results...
X-Some-Date: Mon, 16 Feb 2009 08:58:51 GMT
*/Re: How to add a custom header - Using 4.0.0-b5
Thanks, That worked great with one exception.
The headers added were not listed in the order they were added.
I am planning on using these items to handle bounce processing I would like to maintain them in a certain order for ease of scripting parse searches.
Let me know if there is a (or will be) mechanism to control the order. Otherwise I'll attack it from the bounce processing side.
Thanks,
Kevin
The headers added were not listed in the order they were added.
I am planning on using these items to handle bounce processing I would like to maintain them in a certain order for ease of scripting parse searches.
Let me know if there is a (or will be) mechanism to control the order. Otherwise I'll attack it from the bounce processing side.
Thanks,
Kevin
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: How to add a custom header - Using 4.0.0-b5
Mail servers can change the order of the headers, so even if Swift puts them in a particular order you can't guarantee that they'll arrive in that orderKevinC wrote:Thanks, That worked great with one exception.
The headers added were not listed in the order they were added.
I am planning on using these items to handle bounce processing I would like to maintain them in a certain order for ease of scripting parse searches.
Let me know if there is a (or will be) mechanism to control the order. Otherwise I'll attack it from the bounce processing side.
Thanks,
Kevin
There is a way to get Swift to put them in a particular order however... I'll have to dig up the code so I'll post back when I'm a little less busy
Code: Select all
$message->getHeaders()->defineOrdering(array(
'To',
'Cc',
'Bcc',
'Subject',
'My-Custom-Header',
'Another-Header',
'Content-Type',
'MIME-Version',
'Message-ID'
));You can check what order Swift puts them in prior to sending by doing:
Code: Select all
echo $message->toString();Re: How to add a custom header - Using 4.0.0-b5
Actually I was only worried about the additional header elements that I added using:
$message->getHeaders()->addTextHeader('Name-Of-Header', 'value of header');
Thanks
Kevin
$message->getHeaders()->addTextHeader('Name-Of-Header', 'value of header');
Thanks
Kevin
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: How to add a custom header - Using 4.0.0-b5
The same principle applies. However, using that call that I posted above, with only you new header names will override Swift Mailer's defaults (which includes To: and Subject: header etc). This shouldn't cause any issues, but if it's not desirable we may have modify the interface to allow this to be handled a little better.KevinC wrote:Actually I was only worried about the additional header elements that I added using:
$message->getHeaders()->addTextHeader('Name-Of-Header', 'value of header');
Thanks
Kevin
My gawd, it's so tricky trying to account for everybody's needs