Zend_Mail-MultipleEmails.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 20039 -->
  4. <sect1 id="zend.mail.multiple-emails">
  5. <title>SMTP 接続による複数のメールの送信</title>
  6. <para>
  7. デフォルトでは、ひとつの SMTP トランスポートが
  8. ひとつの接続を作成し、スクリプトの実行中はそれを使いまわします。
  9. この SMTP 接続で、複数のメールを送信できます。
  10. SMTP のハンドシェイクを正しく行うには、
  11. メッセージの配送の前に RSET コマンドを発行します。
  12. </para>
  13. <!-- TODO : to be translated -->
  14. <para>
  15. Optionally, you can also define a default From email address and name,
  16. as well as a default reply-to header. This can be done through the static
  17. methods <methodname>setDefaultFrom()</methodname> and
  18. <methodname>setDefaultReplyTo()</methodname>. These defaults will be used when you
  19. don't specify a From/Reply-to Address or -Name until the defaults are reset (cleared).
  20. Resetting the defaults can be done through the use of the
  21. <methodname>clearDefaultFrom()</methodname> and
  22. <methodname>clearDefaultReplyTo</methodname>.
  23. </para>
  24. <example id="zend.mail.multiple-emails.example-1">
  25. <title>SMTP 接続による複数のメールの送信</title>
  26. <programlisting language="php"><![CDATA[
  27. // トランスポートを作成します
  28. $config = array('name' => 'sender.example.com');
  29. $transport = new Zend_Mail_Transport_Smtp('mail.example.com', $config);
  30. // 送信するメール全てで使う From 及び Reply-To のアドレス及び名前を設定します
  31. Zend_Mail::setDefaultFrom('sender@example.com', 'John Doe');
  32. Zend_Mail::setDefaultReplyTo('replyto@example.com','Jane Doe');
  33. // メッセージをループ処理します
  34. for ($i = 0; $i < 5; $i++) {
  35. $mail = new Zend_Mail();
  36. $mail->addTo('studio@example.com', 'Test');
  37. $mail->setSubject(
  38. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  39. );
  40. $mail->setBodyText('...Your message here...');
  41. $mail->send($transport);
  42. }
  43. // 既定値をリセットします
  44. Zend_Mail::clearDefaultFrom();
  45. Zend_Mail::clearDefaultReplyTo();
  46. ]]></programlisting>
  47. </example>
  48. <para>
  49. 各配送ごとに別々の接続を使用したい場合は、
  50. <methodname>send()</methodname> メソッドのコールの前後に
  51. トランスポートの作成と廃棄をする必要があります。
  52. あるいは、トランスポートのプロトコルオブジェクトを用いて
  53. 各配送の接続を操作することもできます。
  54. </para>
  55. <example id="zend.mail.multiple-emails.example-2">
  56. <title>トランスポートの接続の手動制御</title>
  57. <programlisting language="php"><![CDATA[
  58. // トランスポートを作成します
  59. $transport = new Zend_Mail_Transport_Smtp();
  60. $protocol = new Zend_Mail_Protocol_Smtp('mail.example.com');
  61. $protocol->connect();
  62. $protocol->helo('sender.example.com');
  63. $transport->setConnection($protocol);
  64. // メッセージをループ処理します
  65. for ($i = 0; $i < 5; $i++) {
  66. $mail = new Zend_Mail();
  67. $mail->addTo('studio@example.com', 'Test');
  68. $mail->setFrom('studio@example.com', 'Test');
  69. $mail->setSubject(
  70. 'Demonstration - Sending Multiple Mails per SMTP Connection'
  71. );
  72. $mail->setBodyText('...Your message here...');
  73. // 手動で接続を制御します
  74. $protocol->rset();
  75. $mail->send($transport);
  76. }
  77. $protocol->quit();
  78. $protocol->disconnect();
  79. ]]></programlisting>
  80. </example>
  81. </sect1>
  82. <!--
  83. vim:se ts=4 sw=4 et:
  84. -->