Opinion about sending letters with php

I am preparing a site that will send email notifications to registered users. In my experience, I know that sending emails is a bit of a painful process for PHP, especially when we talk about thousands. One of my websites emails from time to time to 1000-1500 people. It takes about 5 minutes for PHP to do this, so we run it overnight when the server load is the lowest. I use the built-in mail() function without SMTP. This works fine on a dedicated server, but I am not a big fan of this solution.

I want to be able to send such amounts at any time, without risking going down to the server (and it will be blacklisted).
I read that the ideal solution is to send letters in batches (say, 20) every couple of minutes with a script that runs Cron. This seems like a really reasonable idea to me, but ... What if I donโ€™t have access to Cron (not all hosting providers provide access to it) and the website is not popular enough to run the script on the download page?

I insist on using my server for mailing, and not for any external solution.

PS. I found such solutions: http://www.mywebcron.com/ , but is this good?


EDIT

Just add:

  • I am using CodeIgniter,
  • the rate at which emails are sent from my current server is usually 0.2 seconds. by email.
+7
php email cron codeigniter
source share
2 answers

Using a PHP mailer class such as PHPmailer or SwiftMailer , you can send mail directly through SMTP in a way that will be much faster. And yes, sending a large number of emails is best done through cron, so you send X emails every minute. This way you avoid server overload. If you canโ€™t create cron jobs on your server, I suggest you switch the hosting provider, otherwise the website associated with you will be your only viable alternative (but you, depending on some third party, this is not very cool)

+3
source share

If you cannot use a periodic task, you may need to find a solution for the queue, such as Gearman.

What would you like to do is send all your emails to the queue and have 1 or more long-term workers who select jobs from the queue. If you want to add a delay to the system, just add sleep there.

Some really basic pseudo codes:

 #wherever you launch the jobs from for each user gearman.push(user.generateEmail()) #in your consumer script while true message = gearman.consume() message.send() sleep(5) 
+2
source share

All Articles