Programmer's Reference Guide
| SMTP 経由での送信 |
SMTP 接続による複数のメールの送信
デフォルトでは、ひとつの SMTP トランスポートが ひとつの接続を作成し、スクリプトの実行中はそれを使いまわします。 この SMTP 接続で、複数のメールを送信できます。 SMTP のハンドシェイクを正しく行うには、 メッセージの配送の前に RSET コマンドを発行します。
任意で、既定の reply-to ヘッダだけではなく、既定の email アドレスと名前も 定義できます。これは静的メソッド setDefaultFrom() 及び setDefaultReplyTo() を介して行なわれます。 これらの既定値は、既定値がリセット(消去)されるまで、 From/Reply-to のアドレスや 名前を指定しない場合に使われます。 既定値は clearDefaultFrom() 及び clearDefaultReplyTo を使って消去されます。
例1 SMTP 接続による複数のメールの送信
- // トランスポートを作成します
- $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();
各配送ごとに別々の接続を使用したい場合は、 send() メソッドのコールの前後に トランスポートの作成と廃棄をする必要があります。 あるいは、トランスポートのプロトコルオブジェクトを用いて 各配送の接続を操作することもできます。
例2 トランスポートの接続の手動制御
- // トランスポートを作成します
- $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();
| SMTP 経由での送信 |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.

Comments
For my opinion if we create object before the loop so for the each new message will be added new address.
more:
http://framework.zend.com/manual/en/zend.mail.adding-recipients.html
Zend_Mail_Transport_Smtp. Save yourself the 3hours of headache.SPECIFY
[b]'auth' => 'login'[/b]in the config options$config = array(
'auth' => 'login',
'username' => $username,
'password' => $password);