Zend_Mail attachment missing line October 14, 2008
Posted by ordinarywebguy in PHP, Zend Framework.trackback
If you may ever find hard to make it work using Zend_Mail file attachment and following the documentation here http://framework.zend.com/manual/en/zend.mail.attachments.html, there’s a missing line.
$mail = new Zend_Mail();
$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;$mail->send();
This should be
$mail = new Zend_Mail();
$myImage = file_get_contents($myImagePath);
$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;$mail->send();
This should work fine now.

thank!
Thanks for the info regarding the missing line…definitely useful. Note, however, that in my case, after I added the file_get_contents() function, I still had another modification to make it work…it needed different encoding: ENCODING_BASE64…
below is the sample code that workd for me…
$binaryFileToAttach = file_get_contents(‘./boat.jpg’);
$at = $mail->createAttachment($binaryFileToAttach);
$at->type = ‘image/jpeg’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = ‘test3434.jpg’;
That is weird that no one at framework page didn’t notice that…