ZF2-507: Invalid Date header set in mail Message

Issue Type: Bug Created: 2012-08-29T14:43:46.000+0000 Last Updated: 2012-08-31T19:46:11.000+0000 Status: Resolved Fix version(s): - Next Mini Release (04/Oct/12)

Reporter: EPOKMEDIA (epokmedia) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\Mail

Related issues: Attachments:


Here is the code from Zend\Mail\Message :

<pre class="highlight"> 
public function getHeaders()
        if (null === $this->headers) {
            $this->setHeaders(new Headers());
            $this->headers->addHeaderLine('Date', date('r'));
        return $this->headers;

The Date header is added as a GenericHeader. When using UTF-8 encoding, the date header will be converted. This will break the message because date header MUST be in ASCII.

This can be resolved by setting a proper Zend\Mail\Header\Date instance when creating the message headers.

Here is a test case to reproduce the bug :

<pre class="highlight">
     * @group ZF2-507
    public function testDefaultDateHeaderEncodingIsAlwaysAscii()
        $headers = $this->message->getHeaders();
        $header = $headers->get('date');
        $date    = date('r');
        $date    = substr($date, 0, 16);
        $test    = $header->getFieldValue();
        $test    = substr($test, 0, 16);
        $this->assertEquals($date, $test);


Posted by Matthew Weier O'Phinney (matthew) on 2012-08-31T19:37:52.000+0000

Pull request is here:

Posted by Matthew Weier O'Phinney (matthew) on 2012-08-31T19:46:11.000+0000

Merged to release, and will be merged to 2.0.1 and master branches shortly.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.