Issues

ZF-12428: Sending multiple Mails with Zend\Mime\Part (resource based content) failed

Issue Type: Bug Created: 2012-09-28T13:14:03.000+0000 Last Updated: 2012-09-28T14:55:01.000+0000 Status: Closed Fix version(s): Reporter: Andi Dittrich (xaos) Assignee: Frank Brückner (frosch) Tags: - Zend_Mail

  • Zend_Mime

Related issues: Attachments:

Description

Hi, Sorry this is an ZF 2.0.2 Issue .. but i did not find the link to post it within the ZF2 tracker - so please move it to the correct project!

= Description = Using Zend\Mail with Zend\Mime\Part multipart stream based content, multiple calls of Zend\Mail\Transport\Smtp::send results in incomplete mail transmission. Currently, on every call of Zend\Mail\Transport\Smtp::send the content of each part is captured by using Zend\Mime\Part::getContent(), but this function directly gets the stream content by using stream_get_contents(...). When using Resource based content (e.g. create by fopen) only the first readout works. On the second call the filepointer is pointed to the end of the file and stream_get_contents() will return an empty string which results in an empty Part of the Message.

= Example = $sendTo = array('user1@example.tld', 'user2@example.tld', 'user3@example.tld');

// message $message = new Zend\Mail\Message(); ...

// SMTP $transport = new Zend\Mail\Transport\Smtp();

// string based content $text = new Zend\Mime\Part('text...'); ...

// resource based stream content $pdf = new Zend\Mime\Part(fopen('test.pdf', 'r')); ...

// set content $body->setParts(array($text, $pdf)); $message->setBody($body);

// send mails - first mail will be delivered correctly. second+third mail will be transmitted without the $pdf content foreach ($sendTo as $dst){ $message->setBcc($dst); $transport->send($message); }

= Possible Solution = 1.) Zend\Mime\Part::getContent - a flag should be added, that indicates the stream content is read yet. In this case a "cached" version of the stream content should be returned. 2.) Or (the simple way) rewind($this->content) should be called before stream_get_contents to reset the file pointer

Comments

Posted by Frank Brückner (frosch) on 2012-09-28T14:54:46.000+0000

@Andi {quote}Sorry this is an ZF 2.0.2 Issue .. but i did not find the link to post it within the ZF2 tracker - so please move it to the correct project!{quote} Open your report here: https://github.com/zendframework/zf2/issues

Have you found an issue?

See the Overview section for more details.

Copyright

© 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.

Contacts