Zend_Mail-Introduction.xml 5.8 KB

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