ZF-12445: Zend_Mail Header Bug for Linux Machines for ZF 2.0

Issue Type: Bug Created: 2012-10-17T15:31:38.000+0000 Last Updated: 2012-10-22T11:55:18.000+0000 Status: Closed Fix version(s): Reporter: Nikesh Hajari (nikeshhajari) Assignee: Frank Brückner (frosch) Tags: - Zend_Mail

  • zend_mail

Related issues: Attachments:



I have noticed an issue when sending e-mails the headers show up in the e-mail itself. I looked at the EOL character used in the Zend\Mail\Headers class (constant EOL = \r\n) which is perfectly for Windows, but when sending an e-mail with this line break I get the following output in the actual email:

Reply-To: My Test Email

From: John Doe


When the constant is changed to \n ONLY then the output shows up normal (Just Hello). In other words this \r character is causing the headers to show up as plain text in the message body.

My suggestion is to used the PHP_EOL constant so it is automatically adjusted for each platform automatically.…

Thanks, Nikesh


Posted by Nikesh Hajari (nikeshhajari) on 2012-10-17T16:31:50.000+0000


I have figured out more.

Changing line 31 in Zend\Mail\Headers from:

const EOL = "\r\n";


const EOL = PHP_EOL;

will successfully allow me to send e-mails without the above problem occuring.

The following code now works normally:

    $m = new \Zend\Mail\Message();
    $m->addFrom('', 'Jane Doe')
      ->addTo('', 'John Doe')

    $bodyPart = new \Zend\Mime\Message();

    $bodyMessage = new \Zend\Mime\Part($html);
    $bodyMessage->type = 'text/html';



Currently, trying to figure out:

when adding ->setEncoding('UTF-8') and HTML message shows shows up as a mime-attachment.


Posted by Nikesh Hajari (nikeshhajari) on 2012-10-17T16:49:08.000+0000

Figured It Out:

This code here correctly works (UTF-8, HTML E-mail)

$m = new \Zend\Mail\Message(); $m->addFrom('', 'Sam John') ->addTo('', 'John Doe') ->setSubject('Test');

    $bodyPart = new \Zend\Mime\Message();

    $bodyMessage = new \Zend\Mime\Part($html);
    $bodyMessage->type = 'text/html';



NOTE: If the $m->setEncoding('UTF-8') is called BEFORE setting the body the message will not show up correctly.

Two things needs to be fixed:

  1. PHP_EOL compatibility across all systems
  2. You should be able to call setEncoding('UTF-8') at anytime before sending the e-mail.

Posted by Frank Brückner (frosch) on 2012-10-22T11:55:18.000+0000

Please report ZF2 issues at

Have you found an issue?

See the Overview section for more details.


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

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