Hey all, I've been having this thought for a while. What is the best way to run a mailing list on PHP? I have a couple of membership websites, all of them have around 2.000 - 5.000 subscribers. How should I run a mailing list? I'm planning to run one weekly list and one daily list. The content of the letter will be dynamically generated with PHP / MySQL. Any suggestions?
PHP list? I use Aweber for managing lists. It's a paid service, but really powerful. Take a look at both.
Any more suggestions? The problem is... I don't know how to delay a process in PHP? For example, I have 5k subscribers, and I need to send like 100 e-mails every 5 minutes. I would like to set the starting time via Cron Jobs, like 03:00AM, and the PHP script will send 100 e-mails, wait for 5 minutes and then send another 100. And do this till it's all over. Is that possible?
There are loads of ways to do it. My personal way would be: Using two cron jobs. Cron Job 1 will run every 5 min. Cron Job 2 will run every time you want it to start such as 3.00am And one database containing a minimum of: - email address - sent How it works: Cron two runs and sets all of the database entrys "sent" field to false. Cron one runs and searches the database for the first 100 entries that have "sent" set to false, it then sends emails to all these, and marks "sent" to true. 5 min later cron one runs again and finds the next load of emails to send, and so on untill completed. Finally cron two will come around again, clear all of the "sent" to false, and the whole process will be restarted. I am not sure this is the best way or even if it would defo work. Regards, Tom
+ Just limit the results using the limit clause after applying the where statement like: Select * from mails where sent="false" LIMIT 0, 100 Code (markup): That should do it I hope, using limit clause after a while....
Try this: add 1 field to table which stores emails. (last_letter_id) Store the newsletter in a table. Set a cron 5-10 minutes. This is what it does: 1> checks last letter id in table that stores newsletter. 2> Checks which members have last_letter_id set to less than this new id. limit 50 or more " select userid, email from table where last_letter_id!='$id' limit 50" $userid= userid from table 3> send email to them, and update last_letter_id "update membertable set last_letter_id='$id' where userid='$userid' limit 1 " If you need help with this, I can write the script for $10, but need ftp access to check tables and check if script is functioning properly. regards
I would like to hear the opinion of a server expert... Will the "every 5 minutes" cron job affect the server's performance? If for example the script will run (send e-mails) just 20 times, will running this cron check every 5 minutes do any bad?
Not a server expert , but there is the sleep() function in php. You'd need (I *think*) to use set_time_limit() to put the maximum execution time for a php script up, so that the script doesn't sleep() for 30 seconds out of the 5 mins and then get shut down automatically. Using php would be easiest if you're atall familiar with it, but cron jobs would probably be slightly less resource-intensive (though compared to one2three's idea, it has the advantage of not running a script and checking the database every 5 minutes of every day, with most of those runs ending up not doing anything). Something like this perhaps: <?php set_time_limit(0); $dbConn = mysql_connect('localhost', 'your-user-here', 'your-pass-here', 'your-db-here'); $dbQuery = 'SELECT * FROM `YourTable` LIMIT '; $dbCount = mysql_result('SELECT COUNT(`YourIDFieldHere`) FROM `YourTable`', 0); for($Run = 0; $Run <= $dbCount; $Run++) { $dbLimit = ($Run * 30).', 30'; $dbResult = mysql_fetch_assoc(mysql_query($dbQuery.$dbRow)); your-mail-function-here($dbResult); sleep(300); } ?> PHP: That probably has errors in, even once you've filled in what's missing, but you get the idea.
running a php script via cron every 5 minutes isn't going to hamper performance. Its going to be a better method than leaving a php script running constantly, which I doubt you could do anyway, the set_time_limit option isn't going to be available under most shared hosting plans. So it would time out. Also you might want to spread those emails out a little bit more. I seem to remember anything over 500/hour is considered excessive by most webhosts. If you're lucky they will ask you about it. If my mailing list was opt-in and I could prove it, I'd do up to 1,000 an hour just to spread out the load.
I would also use something like PHPMailer that allows you to log into a legit email account on your domain to send the emails from. That way you bypass the quota that most shared hosting uses. There are other things as well to check, for instance sending to Yahoo email addresses all at once can get you blacklisted. Try not to flood a single server to much, spread them out. If possible send from multiple email servers. But yes a cron job is what I would do. If your sending html emails though you got to make sure it at least works for the main email clients like Outlook etc etc. DaDa mail is a nice script to use.
Yeah, I talked with a couple of server administrators, all of them are in the favor of Cron Jobs, the plan that one2three mentioned earlier. All of them however noted this: the e-mails should be correctly constructed. It is mandatory to have a "to unsubscribe, do this" phrase. Otherwise it will be trouble. Anyway, thank you all for the input, you've all been helpful