Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Mail Laravel Package

zendframework/zend-mail

Zend\Mail provides robust email composition and transport for PHP applications, supporting MIME messages, attachments, multipart content, headers, encodings, and SMTP/sendmail/file transports. Includes message parsing and validation for reliable mail handling.

View on GitHub
Deep Wiki
Context7

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.

Examples

Sending Multiple Mails per SMTP Connection

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

// Create transport
$transport = new Smtp([
    'host' => 'mail.example.com'
]);

// Create a base message:
$template = new Message();
$template->addFrom('sender@example.com', 'John Doe');
$template->addReplyTo('replyto@example.com', '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;
    $message->addTo($address);

    $transport->send($message);
}

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('mail.example.com');
$protocol->connect();
$protocol->helo('sender.example.com');

$transport->setConnection($protocol);

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

    // Manually control the connection
    $protocol->rset();
    $transport->send($message);
}

$protocol->quit();
$protocol->disconnect();
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4