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

Description

Hello,

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 test@myemail.com

From: John Doe john@stuff.com

Hello

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.

http://stackoverflow.com/questions/128560/…

Thanks, Nikesh

Comments

Hello,

I have figured out more.

Changing line 31 in Zend\Mail\Headers from:

const EOL = "\r\n";

TO

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('test@me.com', 'Jane Doe')
      ->addTo('test@you.com', 'John Doe')
      ->setSubject('Test');


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

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

    $bodyPart->setParts(array($bodyMessage));

    $m->setBody($bodyPart);

Currently, trying to figure out:

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

-Nikesh

Figured It Out:

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

$m = new \Zend\Mail\Message(); $m->addFrom('sam@test.edu', 'Sam John') ->addTo('john@test.edu', 'John Doe') ->setSubject('Test');

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

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

    $bodyPart->setParts(array($bodyMessage));

    $m->setBody($bodyPart);
    $m->setEncoding('UTF-8');

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 https://github.com/zendframework/zf2/issues