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