Zend_Mail-Attachments.xml 2.1 KB

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