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

Laminas Mail Laravel Package

oroinc/laminas-mail

oroinc/laminas-mail is a small bridge package for using Laminas Mail components within Oro applications. Provides the Laminas mail classes and configuration needed to send emails, manage transports, and integrate with Oro’s mailing features.

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 Laminas\Mail\Message;
use Laminas\Mail\Transport\Smtp;

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

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

// Loop through recipients:
foreach ($recipients as $address) {
    $message->setTo($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 Laminas\Mail\Message;
use Laminas\Mail\Protocol\Smtp as SmtpProtocol;
use Laminas\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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky