| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <!-- EN-Revision: 20039 -->
- <sect1 id="zend.mail.multiple-emails">
- <title>SMTP 接続による複数のメールの送信</title>
- <para>
- デフォルトでは、ひとつの SMTP トランスポートが
- ひとつの接続を作成し、スクリプトの実行中はそれを使いまわします。
- この SMTP 接続で、複数のメールを送信できます。
- SMTP のハンドシェイクを正しく行うには、
- メッセージの配送の前に RSET コマンドを発行します。
- </para>
- <!-- TODO : to be translated -->
- <para>
- Optionally, you can also define a default From email address and name,
- as well as a default reply-to header. This can be done through the static
- methods <methodname>setDefaultFrom()</methodname> and
- <methodname>setDefaultReplyTo()</methodname>. These defaults will be used when you
- don't specify a From/Reply-to Address or -Name until the defaults are reset (cleared).
- Resetting the defaults can be done through the use of the
- <methodname>clearDefaultFrom()</methodname> and
- <methodname>clearDefaultReplyTo</methodname>.
- </para>
- <example id="zend.mail.multiple-emails.example-1">
- <title>SMTP 接続による複数のメールの送信</title>
- <programlisting language="php"><![CDATA[
- // トランスポートを作成します
- $config = array('name' => 'sender.example.com');
- $transport = new Zend_Mail_Transport_Smtp('mail.example.com', $config);
- // 送信するメール全てで使う From 及び Reply-To のアドレス及び名前を設定します
- Zend_Mail::setDefaultFrom('sender@example.com', 'John Doe');
- Zend_Mail::setDefaultReplyTo('replyto@example.com','Jane Doe');
- // メッセージをループ処理します
- for ($i = 0; $i < 5; $i++) {
- $mail = new Zend_Mail();
- $mail->addTo('studio@example.com', 'Test');
- $mail->setSubject(
- 'Demonstration - Sending Multiple Mails per SMTP Connection'
- );
- $mail->setBodyText('...Your message here...');
- $mail->send($transport);
- }
- // 既定値をリセットします
- Zend_Mail::clearDefaultFrom();
- Zend_Mail::clearDefaultReplyTo();
- ]]></programlisting>
- </example>
- <para>
- 各配送ごとに別々の接続を使用したい場合は、
- <methodname>send()</methodname> メソッドのコールの前後に
- トランスポートの作成と廃棄をする必要があります。
- あるいは、トランスポートのプロトコルオブジェクトを用いて
- 各配送の接続を操作することもできます。
- </para>
- <example id="zend.mail.multiple-emails.example-2">
- <title>トランスポートの接続の手動制御</title>
- <programlisting language="php"><![CDATA[
- // トランスポートを作成します
- $transport = new Zend_Mail_Transport_Smtp();
- $protocol = new Zend_Mail_Protocol_Smtp('mail.example.com');
- $protocol->connect();
- $protocol->helo('sender.example.com');
- $transport->setConnection($protocol);
- // メッセージをループ処理します
- for ($i = 0; $i < 5; $i++) {
- $mail = new Zend_Mail();
- $mail->addTo('studio@example.com', 'Test');
- $mail->setFrom('studio@example.com', 'Test');
- $mail->setSubject(
- 'Demonstration - Sending Multiple Mails per SMTP Connection'
- );
- $mail->setBodyText('...Your message here...');
- // 手動で接続を制御します
- $protocol->rset();
- $mail->send($transport);
- }
- $protocol->quit();
- $protocol->disconnect();
- ]]></programlisting>
- </example>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|