phpperformancesmtpphpmailerpersistent-connection

Persistent SMTP connection in PHPMailer


How to enable persistent SMTP connections in PHPMailer?

I will send many emails, so with persistent connections probably I will get performance gain.


Solution

  • We really don't care here if your server gets blacklisted, right? This is how to achieve what you want. Just set to true the SMTPKeepAlive property and after the bulk sending, call implicitly the SmtpClose() method.

    $phpMailer = New PHPMailer();
    $phpMailer->isSMTP();
    $phpMailer->SMTPKeepAlive = true;
    
    for ( ... ) {
        // Send your emails right away
        [ ... ]
    }
    
    $phpMailer->SmtpClose();