Zend_Mail-Attachments.xml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.mail.attachments">
  4. <title>Attachments</title>
  5. <para>
  6. Files can be attached to an e-mail using the <methodname>createAttachment()</methodname>
  7. method. The default behavior of <classname>Zend_Mail</classname> is to assume the
  8. attachment is a binary object (<property>application/octet-stream</property>), that it
  9. should be transferred with base64 encoding, and that it is handled as an attachment. These
  10. assumptions can be overridden by passing more parameters to
  11. <methodname>createAttachment()</methodname>:
  12. </para>
  13. <example id="zend.mail.attachments.example-1">
  14. <title>E-Mail Messages with Attachments</title>
  15. <programlisting language="php"><![CDATA[
  16. $mail = new Zend_Mail();
  17. // build message...
  18. $mail->createAttachment($someBinaryString);
  19. $mail->createAttachment($myImage,
  20. 'image/gif',
  21. Zend_Mime::DISPOSITION_INLINE,
  22. Zend_Mime::ENCODING_BASE64);
  23. ]]></programlisting>
  24. </example>
  25. <para>
  26. If you want more control over the <acronym>MIME</acronym> part generated for this
  27. attachment you can use the return value of <methodname>createAttachment()</methodname> to
  28. modify its attributes. The <methodname>createAttachment()</methodname> method returns a
  29. <classname>Zend_Mime_Part</classname> object:
  30. </para>
  31. <programlisting language="php"><![CDATA[
  32. $mail = new Zend_Mail();
  33. $at = $mail->createAttachment($myImage);
  34. $at->type = 'image/gif';
  35. $at->disposition = Zend_Mime::DISPOSITION_INLINE;
  36. $at->encoding = Zend_Mime::ENCODING_BASE64;
  37. $at->filename = 'test.gif';
  38. $mail->send();
  39. ]]></programlisting>
  40. <para>
  41. An alternative is to create an instance of <classname>Zend_Mime_Part</classname> and add it
  42. with <methodname>addAttachment()</methodname>:
  43. </para>
  44. <programlisting language="php"><![CDATA[
  45. $mail = new Zend_Mail();
  46. $at = new Zend_Mime_Part($myImage);
  47. $at->type = 'image/gif';
  48. $at->disposition = Zend_Mime::DISPOSITION_INLINE;
  49. $at->encoding = Zend_Mime::ENCODING_BASE64;
  50. $at->filename = 'test.gif';
  51. $mail->addAttachment($at);
  52. $mail->send();
  53. ]]></programlisting>
  54. </sect1>
  55. <!--
  56. vim:se ts=4 sw=4 et:
  57. -->