Files can be attached to an e-mail using the addAttachment()
method. The default behaviour
of Zend_Mail
is to assume the attachment is a binary object (application/octet-stream),
should be transferred with base64 encoding, and is handled as an attachment. These assumptions can be
overridden by passing more parameters to addAttachment()
:
Example 9.6. E-Mail Messages with Attachments
<?php require_once 'Zend/Mail.php'; $mail = new Zend_Mail(); // build message... $mail->addAttachment($someBinaryString); $mail->addAttachment($myImage, 'image/gif', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_8BIT); ?>
If you want more control over the MIME part generated for this attachment you can use the return value
of addAttachment()
to modify its attributes. The addAttachment()
method
returns a Zend_Mime_Part
object:
<?php require_once 'Zend/Mail.php'; $mail = new Zend_Mail(); // build message... $at = $mail->addAttachment($myImage); $at->type = 'image/gif'; $at->id = 12; $at->filename ='test.gif'; //... $mail->send(); ?>