Persistent SMTP connection in PHPMailer

Paulo Coghi picture Paulo Coghi · Feb 25, 2010 · Viewed 18k times · Source

How to enable persistent SMTP connections in PHPMailer?

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

Answer

Mauro picture Mauro · Mar 26, 2011

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();