Zend_Mail-Introduction.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.mail.introduction">
  4. <title>Introduction</title>
  5. <sect2 id="zend.mail.introduction.getting-started">
  6. <title>Getting started</title>
  7. <para>
  8. <classname>Zend_Mail</classname> provides generalized functionality to compose and send
  9. both text and <acronym>MIME</acronym>-compliant multipart e-mail messages. Mail can be
  10. sent with <classname>Zend_Mail</classname> via the default
  11. <classname>Zend_Mail_Transport_Sendmail</classname> transport or via
  12. <classname>Zend_Mail_Transport_Smtp</classname>.
  13. </para>
  14. <example id="zend.mail.introduction.example-1">
  15. <title>Simple E-Mail with Zend_Mail</title>
  16. <para>
  17. A simple e-mail consists of some recipients, a subject, a body and a sender. To send
  18. such a mail using <classname>Zend_Mail_Transport_Sendmail</classname>, do the
  19. following:
  20. </para>
  21. <programlisting language="php"><![CDATA[
  22. $mail = new Zend_Mail();
  23. $mail->setBodyText('This is the text of the mail.');
  24. $mail->setFrom('somebody@example.com', 'Some Sender');
  25. $mail->addTo('somebody_else@example.com', 'Some Recipient');
  26. $mail->setSubject('TestSubject');
  27. $mail->send();
  28. ]]></programlisting>
  29. </example>
  30. <note>
  31. <title>Minimum definitions</title>
  32. <para>
  33. In order to send an e-mail with <classname>Zend_Mail</classname> you have to specify
  34. at least one recipient, a sender (e.g., with <methodname>setFrom()</methodname>),
  35. and a message body (text and/or <acronym>HTML</acronym>).
  36. </para>
  37. </note>
  38. <para>
  39. For most mail attributes there are "get" methods to read the information stored in the
  40. mail object. for further details, please refer to the <acronym>API</acronym>
  41. documentation. A special one is <methodname>getRecipients()</methodname>. It returns an
  42. array with all recipient e-mail addresses that were added prior to the method call.
  43. </para>
  44. <para>
  45. For security reasons, <classname>Zend_Mail</classname> filters all header fields to
  46. prevent header injection with newline (<emphasis>\n</emphasis>) characters.
  47. Double quotation is changed to single quotation and angle brackets to square brackets in
  48. the name of sender and recipients. If the marks are in email address, the marks will be
  49. removed.
  50. </para>
  51. <para>
  52. You also can use most methods of the <classname>Zend_Mail</classname> object with a
  53. convenient fluent interface.
  54. </para>
  55. <programlisting language="php"><![CDATA[
  56. $mail = new Zend_Mail();
  57. $mail->setBodyText('This is the text of the mail.')
  58. ->setFrom('somebody@example.com', 'Some Sender')
  59. ->addTo('somebody_else@example.com', 'Some Recipient')
  60. ->setSubject('TestSubject')
  61. ->send();
  62. ]]></programlisting>
  63. </sect2>
  64. <sect2 id="zend.mail.introduction.sendmail">
  65. <title>Configuring the default sendmail transport</title>
  66. <para>
  67. The default transport for a <classname>Zend_Mail</classname> instance is
  68. <classname>Zend_Mail_Transport_Sendmail</classname>. It is essentially a wrapper to the
  69. <acronym>PHP</acronym> <ulink
  70. url="http://php.net/mail"><methodname>mail()</methodname></ulink> function. If you
  71. wish to pass additional parameters to the <ulink
  72. url="http://php.net/mail"><methodname>mail()</methodname></ulink> function, simply
  73. create a new transport instance and pass your parameters to the constructor. The new
  74. transport instance can then act as the default <classname>Zend_Mail</classname>
  75. transport, or it can be passed to the <methodname>send()</methodname> method of
  76. <classname>Zend_Mail</classname>.
  77. </para>
  78. <example id="zend.mail.introduction.sendmail.example-1">
  79. <title>
  80. Passing additional parameters to the Zend_Mail_Transport_Sendmail transport
  81. </title>
  82. <para>
  83. This example shows how to change the Return-Path of the <ulink
  84. url="http://php.net/mail"><methodname>mail()</methodname></ulink> function.
  85. </para>
  86. <programlisting language="php"><![CDATA[
  87. $tr = new Zend_Mail_Transport_Sendmail('-freturn_to_me@example.com');
  88. Zend_Mail::setDefaultTransport($tr);
  89. $mail = new Zend_Mail();
  90. $mail->setBodyText('This is the text of the mail.');
  91. $mail->setFrom('somebody@example.com', 'Some Sender');
  92. $mail->addTo('somebody_else@example.com', 'Some Recipient');
  93. $mail->setSubject('TestSubject');
  94. $mail->send();
  95. ]]></programlisting>
  96. </example>
  97. <note>
  98. <title>Safe mode restrictions</title>
  99. <para>
  100. The optional additional parameters will be cause the <ulink
  101. url="http://php.net/mail"><methodname>mail()</methodname></ulink> function to
  102. fail if <acronym>PHP</acronym> is running in safe mode.
  103. </para>
  104. </note>
  105. <warning>
  106. <title>Sendmail Transport and Windows</title>
  107. <para>
  108. As the <acronym>PHP</acronym> manual states the <methodname>mail()</methodname>
  109. function has different behaviour on Windows and on *nix based systems. Using the
  110. Sendmail Transport on Windows will not work in combination with
  111. <methodname>addBcc()</methodname>. The <methodname>mail()</methodname> function will
  112. sent to the BCC recipient such that all the other recipients can see him as
  113. recipient!
  114. </para>
  115. <para>
  116. Therefore if you want to use BCC on a windows server, use the SMTP
  117. transport for sending!
  118. </para>
  119. </warning>
  120. </sect2>
  121. </sect1>
  122. <!--
  123. vim:se ts=4 sw=4 et:
  124. -->