Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 995
Paulo Coghi Avatar asked Feb 25 '10 12:02

Paulo Coghi


People also ask

Does PHPMailer use SMTP?

Local Mail Server Limitation Mail() function usually needs local mail server for sending out emails whereas PHPMailer uses SMTP. Also, you should have authentication credentials.

Why does PHPMailer go to spam?

usually this happens because the sending server is already marked as spam by somebody. The way i found is go to the gmail account mark the item as 'important' in gmail and 'Add to Safe senders' in Outlook. Save this answer. Show activity on this post.

Is it safe to use PHPMailer?

PHPMailer doesn't create/use any SQL itself, nor does it have anything to do with javascript, so it's secure on those fronts.

How do I debug SMTP error?

Enable SMTP debugging and set the debug level in your script as follows: $mail->SMTPDebug = 2; level 1 = client; will show you messages sent by the client. level 2 = client and server; will add server messages, it's the recommended setting.


2 Answers

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();
like image 154
Mauro Avatar answered Oct 07 '22 03:10

Mauro


By optimising the sending of emails, you might open yourself up as being identified as spamming and so cause web servers to block your IP.

How many emails are you sending? It may be better to actually throttle emails sent rather than speed up.

like image 40
Jon Winstanley Avatar answered Oct 07 '22 01:10

Jon Winstanley