[ZF-10089] Zend_Log
[zend.git] / documentation / manual / zh / module_specs / Zend_Mail-Attachments.xml
blob97d25a449b5478be5e137876d8f6c805a7142448
1 <sect1 id="zend.mail.attachments">
2     <title> 附件 </title>
3     <para>
4         使用<code>createAttachment()</code>方法可以将文件附加到邮件中。<code>Zend_Mail</code>会缺省地认为该文件是二进制对象(application/octet-stream),以 base64编码传输, 并且作为邮件的附件处理。通过传递额外的参数给<code>createAttachment()</code>方法可以覆盖上述缺省设定:
5     </para>
6     <example id="zend.mail.attachments.example-1">
7         <title> 带附件的邮件 </title>
8         <programlisting role="php"><![CDATA[<?php
9 require_once 'Zend/Mail.php';
10 $mail = new Zend_Mail();
11 // build message...
12 $mail->createAttachment($someBinaryString);
13 $mail->createAttachment($myImage, 'image/gif', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_8BIT);]]>
14         </programlisting>
15     </example>
16     <para>
17         如果你想得到对此附件MIME段产生的更多控制,你可以使用<code>createAttachment()</code>方法的返回值来修改它的属性。方法<code>createAttachment()</code>返回了一个<code>Zend_Mime_Part</code>对象:
18     </para>
19     <programlisting role="php"><![CDATA[<?php
20 require_once 'Zend/Mail.php';
21 $mail = new Zend_Mail();
23 $at = $mail->createAttachment($myImage);
24 $at->type        = 'image/gif';
25 $at->disposition = Zend_Mime::DISPOSITION_INLINE;
26 $at->encoding    = Zend_Mime::ENCODING_8BIT;
27 $at->filename    = 'test.gif';
29 $mail->send();]]>
30     </programlisting>
31     <para>
32         创建 <code>Zend_Mime_Part</code> 实例和用 <code>addAttachment()</code> 添加它的替代方案:
33     </para>
34     <programlisting role="php"><![CDATA[<?php
35 require_once 'Zend/Mail.php';
36 $mail = new Zend_Mail();
38 $at = new Zend_Mime_Part($myImage);
39 $at->type        = 'image/gif';
40 $at->disposition = Zend_Mime::DISPOSITION_INLINE;
41 $at->encoding    = Zend_Mime::ENCODING_8BIT;
42 $at->filename    = 'test.gif';
44 $mail->addAttachment($at);
46 $mail->send();]]>
47     </programlisting>
48 </sect1>
49 <!--
50 vim:se ts=4 sw=4 et:
51 -->