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