What are some best practices for optimizing the delivery time of emails to a large number of recipients using PHP?

When sending emails to a large number of recipients using PHP, it's important to optimize the delivery time to ensure efficient and timely distribution. One way to achieve this is by using a queue system to stagger the delivery of emails, preventing server overload and maximizing deliverability.

// Example PHP code for optimizing email delivery time using a queue system

// Define an array of email addresses
$recipients = array('recipient1@example.com', 'recipient2@example.com', 'recipient3@example.com');

// Loop through the recipients and add emails to the queue with a delay
foreach ($recipients as $recipient) {
    $delay = 5; // Set a delay of 5 seconds between each email
    $command = "echo 'Your email content' | mail -s 'Your email subject' $recipient";
    shell_exec("at now + $delay seconds <<< '$command'");
}