Sending Multiple Mails per SMTP Connection

By default, a single SMTP transport creates a single connection and re-uses it for the lifetime of the script execution. You may send multiple e-mails through this SMTP connection. A RSET command is issued before each delivery to ensure the correct SMTP handshake is followed.


Sending Multiple Mails per SMTP Connection

use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp;

// Create transport
$transport = new Smtp([
    'host' => ''

// Create a base message:
$template = new Message();
$template->addFrom('', 'John Doe');
$template->addReplyTo('', 'Jane Doe');
$template->setSubject('Demo of multiple mails per SMTP connection');
$template->setBody('... Your message here ...');

// Loop through recipients:
foreach ($recipients as $address) {
    // Clone the message and add a recipient:
    $message = clone $template;


If you wish to have a separate connection for each mail delivery, you will need to create and destroy your transport before and after each send() method is called.

Manipulating the transport between messages

You can manipulate the connection between each delivery by accessing the transport's protocol object.

use Zend\Mail\Message;
use Zend\Mail\Protocol\Smtp as SmtpProtocol;
use Zend\Mail\Transport\Smtp as SmtpTransport;

// Create transport
$transport = new SmtpTransport();

$protocol = new SmtpProtocol('');


// Loop through messages
foreach ($recipients as $address) {
    $mail = new Message();
    $mail->setFrom('', 'Test');
        'Demonstration - Sending Multiple Mails per SMTP Connection'
    $mail->setBodyText('...Your message here...');

    // Manually control the connection