SMTP 接続による複数のメールの送信
デフォルトでは、ひとつの SMTP トランスポートが
ひとつの接続を作成し、スクリプトの実行中はそれを使いまわします。
この SMTP 接続で、複数のメールを送信できます。
SMTP のハンドシェイクを正しく行うには、
メッセージの配送の前に RSET コマンドを発行します。
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 setDefaultFrom() and
setDefaultReplyTo(). 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
clearDefaultFrom() and
clearDefaultReplyTo.
SMTP 接続による複数のメールの送信
'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();
]]>
各配送ごとに別々の接続を使用したい場合は、
send() メソッドのコールの前後に
トランスポートの作成と廃棄をする必要があります。
あるいは、トランスポートのプロトコルオブジェクトを用いて
各配送の接続を操作することもできます。
トランスポートの接続の手動制御
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();
]]>