Programmer's Reference Guide
| HTML E-Mail |
Attachments
Files can be attached to an e-mail using the createAttachment() method. The default behavior of Zend_Mail is to assume the attachment is a binary object (application/octet-stream), that it should be transferred with base64 encoding, and that it is handled as an attachment. These assumptions can be overridden by passing more parameters to createAttachment():
Example #1 E-Mail Messages with Attachments
- $mail = new Zend_Mail();
- // build message...
- $mail->createAttachment($someBinaryString);
- $mail->createAttachment($myImage,
- 'image/gif',
- Zend_Mime::DISPOSITION_INLINE,
- Zend_Mime::ENCODING_BASE64);
If you want more control over the MIME part generated for this attachment you can use the return value of createAttachment() to modify its attributes. The createAttachment() method returns a Zend_Mime_Part object:
- $mail = new Zend_Mail();
- $at = $mail->createAttachment($myImage);
- $at->type = 'image/gif';
- $at->disposition = Zend_Mime::DISPOSITION_INLINE;
- $at->encoding = Zend_Mime::ENCODING_BASE64;
- $at->filename = 'test.gif';
- $mail->send();
An alternative is to create an instance of Zend_Mime_Part and add it with addAttachment():
- $mail = new Zend_Mail();
- $at = new Zend_Mime_Part($myImage);
- $at->type = 'image/gif';
- $at->disposition = Zend_Mime::DISPOSITION_INLINE;
- $at->encoding = Zend_Mime::ENCODING_BASE64;
- $at->filename = 'test.gif';
- $mail->addAttachment($at);
- $mail->send();
| HTML E-Mail |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.
Select a Version
Languages Available
Components
Search the Manual
Navigation
- Programmer's Reference Guide
- Programmer's Reference Guide
- Zend Framework Reference
- Zend_Mail
- Introduction
- Sending via SMTP
- Sending Multiple Mails per SMTP Connection
- Using Different Transports
- HTML E-Mail
- Attachments
- Adding Recipients
- Controlling the MIME Boundary
- Additional Headers
- Character Sets
- Encoding
- SMTP Authentication
- Securing SMTP Transport
- Reading Mail Messages

Comments
$myImage should be a binary string. A binary string can be obtained with file_get_contents() method. Here is an example:
$myImage = file_get_contents('logo.png');
$at = $mail->createAttachment($myImage);
$at->filename = 'logo.png';
$myImage should be a binary string. A binary string can be obtained with file_get_contents() method. Here is an example:
$myImage = file_get_contents('logo.png');
$at = $mail->createAttachment($myImage);
$at->filename = 'logo.png';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
and $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
so in Thunderbird html mail with embedded images are not displayed.
According to this art. http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html and some wiki art., for embedded images, Zend_Mime::DISPOSITION_INLINE must place image to be part of text/html related MIME boundary, wich is not case.
Is It a Bug or ?
Thank You
khi tôi làm thế này mà vẫn khong send được mail không biết là có lỗi gì hoặc sai ở đâu ?
when I do this and still not send the mail does not know what error or wrong?
$at = new Zend_Mime_Part('/hoc/email/trunk/public/upload/uploads/GsNJNwuI-UM.gif');
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = '/hoc/email/trunk/public/upload/uploads/GsNJNwuI-UM.gif';
$mail->addAttachment($at);
help me
Hi All
I have found a method and all references. The following is an example
$myImage = file_get_contents('upload/uploads/avatar.jpg');
$at = new Zend_Mime_Part($myImage);
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->filename = 'avatar.jpg';
$mail->addAttachment($at);