Sending Multiple Mails per SMTP Connection | Zend_Mail Programmer's Reference Guide | HTML E-Mail
# Using Different Transports In case you want to send different e-mails through different connections, you can also pass the transport object directly to send() without a prior call to setDefaultTransport(). The passed object will override the default transport for the actual send() request. Example #1 Using Different Transports $mail = new Zend_Mail(); // build message... $tr1 = new Zend_Mail_Transport_Smtp('server@example.com'); $tr2 = new Zend_Mail_Transport_Smtp('other_server@example.com'); $mail->send($tr1); $mail->send($tr2); $mail->send(); // use default again Note: Additional transports Additional transports can be written by implementing 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: function recipientFilename($transport) { return $transport->recipients . '_' . mt_rand() . '.tmp'; } $mail = new Zend_Mail(); $mail->addTo('somebody@example.com', 'Some Recipient'); // build message... $tr = new Zend_Mail_Transport_File(array('callback' => 'recipientFilename')); $mail->send($tr); 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.
Sending Multiple Mails per SMTP Connection | Zend_Mail Programmer's Reference Guide | HTML E-Mail