Zend_Mail-Attachments.xml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 24249 -->
  4. <sect1 id="zend.mail.attachments">
  5. <title>ファイルの添付</title>
  6. <para>
  7. メールにファイルを添付するには <methodname>createAttachment()</methodname> メソッドを使用します。
  8. <classname>Zend_Mail</classname> のデフォルト設定では、添付ファイルは
  9. base64 エンコードされたバイナリオブジェクト (<property>application/octet-stream</property>)
  10. として添付されます。この挙動を変更するには、
  11. <methodname>createAttachment()</methodname> に追加のパラメータを指定します。
  12. </para>
  13. <example id="zend.mail.attachments.example-1">
  14. <title>ファイルを添付したメール</title>
  15. <programlisting language="php"><![CDATA[
  16. $mail = new Zend_Mail();
  17. // メッセージを作成します...
  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. 添付ファイル用の <acronym>MIME</acronym> パートを細かく制御するには、
  27. <methodname>createAttachment()</methodname> の返す値を使用してその属性を変更します。
  28. <methodname>createAttachment()</methodname> メソッドの返す値は
  29. <classname>Zend_Mime_Part</classname> オブジェクトです。
  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. もうひとつの方法は、<classname>Zend_Mime_Part</classname> のインスタンスを作成して
  42. それを <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. -->