12.3. Sending Multiple Mails per SMTP Connection

By default, an SMTP connection is established for every e-mail that is sent. If you want to send multiple e-mails through one SMTP connection, you can handle the connect() yourself. If the transport has already established a connection before send() is called, it will be used and will not be closed:

Example 12.3. Sending Multiple Mails per SMTP Connection

<?php
require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
// build message...
require_once 'Zend/Mail/Transport/Smtp.php';
$tr = new Zend_Mail_Transport_Smtp('mail.example.com');
Zend_Mail::setDefaultTransport($tr);
$tr->connect();
for ($i = 0; $i < 5; $i++) {    
$mail->send();
}
$tr->disconnect();
?>