ZF2-496: Attached documents to message objects are corrupt

Issue Type: Bug Created: 2012-08-23T15:36:26.000+0000 Last Updated: 2012-10-08T20:14:49.000+0000 Status: Closed Fix version(s): Reporter: Jurian Sluiman (mithras) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\Mail

  • Zend\Mime

Related issues: Attachments:


See… and this IRC log (23rd August):

{quote} : jurians: I was lookinag at your mail attachment issue. What's interesting is that Zend\Mime, functionally, hasn't changed between ZF1 and ZF2. The only difference is how messages work. I'm guessing there's some difference in how ZF1's mail class did attachments -- in ZF2, I'm simply saying that if we get a Mime\Message as the body to use it.

: jurians: I'll see if I can track it down quickly; if not, it may need to wait for a bugfix release.

: jurians: interesting. In ZF1, Zend_Mail extended Zend_Mime_Message. I'm stymied; no clue why it's not working in ZF1. Only thing I can think of is that Zend_Mail_Transport_Abstract was doing the part assembly (aggregating headers, boundaries, and content), and that Mime\Message doesn't do that naturally. {quote}

Task: attach a document (example a pdf) to the mail message and send it via the transport layer Expected result: attachment can be opened in an email client Actual result: attachment is corrupt and cannot be openend.

Similar code in Zend Framework 1 worked as expected and since then not much changed in the Zend\Mime part.

Example code to reproduce in ZF2:

<pre class="highlight">
$text = new Mime\Part('Hello world');
$text->type = 'text/plain';

$html = new Mime\Part('

Hello world

$html->type = 'text/html';

$data = file_get_contents('/path/to/my/file.pdf');
$pdf  = new Mime\Part($data);
$pdf->type = 'application/pdf';
$pdf->filename = 'My File.pdf';
$pdf->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;

$body = new Mime\Message;
$body->setParts(array($text, $html, $pdf));

$message = new Message;
$message->addTo('some@example', 'John Doe');



Posted by Koen Pieters (koen) on 2012-08-29T11:36:37.000+0000

Found a work-a-round for this, the pdf is encoded '8bit'. If you add encoding as 'quoted-printable' or 'base64' the attachment will work.

<pre class="highlight">
$pdf->encoding = 'quoted-printable'; 

Posted by Matthew Weier O'Phinney (matthew) on 2012-08-29T14:10:29.000+0000

I suspect that ZF1 was making messages quoted-printable by default.

Posted by Jurian Sluiman (mithras) on 2012-08-29T14:17:59.000+0000

I have experimented with base64 encoded mime types, but my guess was to encode it myself.

<pre class="highlight">
$data = file_get_contents('/path/to/my/file.pdf');
$data = base64_encode($data);
$pdf  = new Mime\Part($data);
$pdf->type = 'application/pdf';
$pdf->filename = 'My File.pdf';
$pdf->encoding = Mime\Mime::ENCODING_BASE64;
$pdf->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;

With the comment of Koen I suspect I don't need to encode the data myself. Because I switched to Swift Mailer, it's quite some work to revert it: in the next week I will test this without a base64_encode() from myself.

Posted by Ralph Schindler (ralph) on 2012-10-08T20:14:49.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit:

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.