How to enable persistent SMTP connections in PHPMailer?
I will send many emails, so with persistent connections probably I will get performance gain.
How to enable persistent SMTP connections in PHPMailer?
I will send many emails, so with persistent connections probably I will get performance gain.
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();
$phpMailer->SMTPKeepAlive = true
will only avoid closing the connection on the first email so it doesn't have to be opened on the next. However, the server might be closing the connection anyway and you can't change that. If you need to send email faster, I recommend you use an API based email platform like Mandrill or Mailgun, where you can fire hundreds of emails on a single request. However if you're trying to do SPAM, just forget I helped you, go to your room and thing about what you did. –
Payne ClearAddresses()
within the loop before calling AddAddress()
. See: https://mcmap.net/q/749144/-phpmailer-keep-1-smtp-connection-with-different-receiver-by-email-content –
Elodia 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.
What do you mean by persistent SMTP connection?
First if you send a Email you are connected to the Server until it finishes the job. Secondly if you wanna send many emails (Probably your server will be in the blacklist), you write a loop in your PHP code, whitch fetches all Email adresses and passes them to the phpmailer and finaly sendts them. Thats how i would send mass mails.
Persistent SMTP connection is suitable when you are sending bulk and want to send faster, keeping the SMTP connection alive for specific number of email sends is the good idea, for faster sending. Frequently alternating SMTP connection within the loop can be the way for more controlled sending during IP warming sessions. https://www.mumara.com/persistent-smtp-connection-and-non-persistent-loop/
© 2022 - 2024 — McMap. All rights reserved.