简体   繁体   中英

Time optimization in SMTP mails using PHPMailer

I have developed a PHP code which extracts email addresses from a list and sends emails one after another. I am using the PHPMailer library to send through my Gmail account.

My intention is to send about 5000 emails at a time. (Don't worry, it's not spam. These are notifications about an upcoming event to its attendees.) However, until now my best output is 133 emails where the code runs for 5 minutes. It's very slow. I guess I can extend the execution time with set_time_limit() . Still, it would need around 3 hours to completely finish sending all the emails.

Few clarifications regarding my code: 1. I have kept the SMTP connection alive with SMTPKeepAlive = true; 2. The setup of the email, as well as the connection, is outside the loop. Inside the loop I only extract the email id, pass it to AddAddress and send. 3. I would like to stick to my own code rather than using a mailing list website/software.

Is it possible to optimize the process and finish it within a couple of minutes?

For this amount of email I would use a transactional mail service like SendGrid or something similar, because when you want to send an email (or one email to multiple addresses) trough the service you just need to create a request to the API. And this takes only a few milliseconds contrary to always connecting to the smtp server,~500ms.

Note: I'm not affiliated in any way with SendGrid, I just love their product (and discovered they services in a situation similar to yours). (They have a free 12,000 emails per month plan).

Note2: They also have a php api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM