1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.mail.attachments">
4 <title>Attachments</title>
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>:
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();
21 $mail->createAttachment($someBinaryString);
22 $mail->createAttachment($myImage,
24 Zend_Mime::DISPOSITION_INLINE,
25 Zend_Mime::ENCODING_BASE64);
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:
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';
49 An alternative is to create an instance of <classname>Zend_Mime_Part</classname> and add it
50 with <methodname>addAttachment()</methodname>:
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);