How can the use of a single open SMTP session improve the speed of sending emails to a large recipient list in PHP?

Sending emails to a large recipient list in PHP can be slow if a new SMTP session is opened for each email. To improve speed, you can use a single open SMTP session to send multiple emails, reducing the overhead of establishing a new connection for each message.

// Open a single SMTP session
$smtp = new SMTP('mail.example.com', 587);
$smtp->authenticate('username', 'password');

// Loop through recipient list and send emails
foreach ($recipients as $recipient) {
    $smtp->send('from@example.com', $recipient, 'Subject', 'Message');
}

// Close the SMTP session
$smtp->close();