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



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



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.


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.

Please report ZF2 issues at