Issues

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

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

@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