SMTP 接続による複数のメールの送信

異なる転送手段の使用

複数のメールをそれぞれ別の接続を使用して送信したい場合は、 setDefaultTransport() をコールするかわりに send() にトランスポートオブジェクトを直接わたすことができます。 実際の send() の際に、 渡されたオブジェクトがデフォルトのトランスポートを上書きします。

Example #1 異なる転送手段の使用

  1. span style="color: #808080; font-style: italic;">// メッセージを作成します...
  2. 'server@example.com''other_server@example.com'// もう一度デフォルトを使用します

Note: 転送手段の追加
別の転送手段を用意するには、Zend_Mail_Transport_Interface を実装します。

Using File Transport

Zend_Mail_Transport_File is useful in a development environment or for testing purposes. Instead of sending any real emails it simply dumps the email's body and headers to a file in the filesystem. Like the other transports, it may be configured using Zend_Application_Resource_Mail, or by passing an instance to the send() method of a Zend_Mail instance.

The transport has two optional parameters that can be passed to the constructor or via setOptions() method. The path option specifies the base path where new files are saved. If nothing is set, the transport uses the default system directory for temporary files. The second parameter, callback, defines what PHP callback should be used to generate a filename. As an example, assume we need to use the recipient's email plus some hash as the filename:

  1. span style="color: #ff0000;">'_''.tmp''somebody@example.com', 'Some Recipient');
  2. // build message...
  3. 'callback' => 'recipientFilename'

The resulting file will be something like somebody@example.com_1493362665.tmp

Note: Include randomness in filename generation
When generating filenames, you should inject some sort of randomness into the generation to ensure that the filenames are unique. This is especially important on servers where you may expect high load, as it will ensure that despite a number of requests coming in during the same second or millisecond, the filename will still be unique.


SMTP 接続による複数のメールの送信