Documentation

Attachments - Zend_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

  1. $mail = new Zend_Mail();
  2. // build message...
  3. $mail->createAttachment($someBinaryString);
  4. $mail->createAttachment($myImage,
  5.                         'image/gif',
  6.                         Zend_Mime::DISPOSITION_INLINE,
  7.                         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:

  1. $mail = new Zend_Mail();
  2.  
  3. $at = $mail->createAttachment($myImage);
  4. $at->type        = 'image/gif';
  5. $at->disposition = Zend_Mime::DISPOSITION_INLINE;
  6. $at->encoding    = Zend_Mime::ENCODING_BASE64;
  7. $at->filename    = 'test.gif';
  8.  
  9. $mail->send();

An alternative is to create an instance of Zend_Mime_Part and add it with addAttachment():

  1. $mail = new Zend_Mail();
  2.  
  3. $at = new Zend_Mime_Part($myImage);
  4. $at->type        = 'image/gif';
  5. $at->disposition = Zend_Mime::DISPOSITION_INLINE;
  6. $at->encoding    = Zend_Mime::ENCODING_BASE64;
  7. $at->filename    = 'test.gif';
  8.  
  9. $mail->addAttachment($at);
  10.  
  11. $mail->send();

Previous topic

HTML E-Mail

Next topic

Adding Recipients

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts