the other day i got an order from a customer and he asked me to write a script that can email website articles when he submits them
fist thing he asked was sending emails to all users in a way that doesnt make any problem for his server cause he has lots of users
ok now for making this script i should plan for writing an email script that can send article to all users after submiting a news by the author.
this script should quee emails not to make the server down
and it should works on background and autumatically
nice example of this script can be phpbb3 group mail section
i googled to find something usefull for this script , any php class that can help
what's your sug开发者_开发技巧gestion and how would you write if this order came to you ?
Use cron.
You can have a cron job run every 5 or 10 minutes that will send only a small percentage of emails at a time. That way it runs in the background and won't slam the SMTP server.
The cron script should use a well-tested class such as PHP Mailer or SwiftMailer. Create a cross-reference table that keeps track of which addresses have been emailed which articles.
How many emails will you need to send out?
I recommend throttling yourself per domain. I would first do a sort on all the email addresses by domain, and then create a mechanism to select from each domain while sending. It is important to keep a timer and not to exceed that count. From my experience, I wouldn't recommend more than about 500 per large domain (yahoo, google...) per hour, if you can finish your job in a reasonable amount of time this way. When I worked for a product registration company, the larger domains would shut us down if we sent very many emails per hour as a result of a large campaign.
Another, related question is what level of reliability do you need? Are you just setting up a script to blast out these emails and you don't care what happens, or would you actually like a mail server which interprets error messages (and takes the relevant follow up actions based on this)?
As a general note, make absolutely sure there is some sort of a way to opt-out from these emails. Unless you do this, you are probably being illegal and you will look extremely spam-like. There is also some spam-checking scripts that you can use (unfortunately, I don't remember the name).
I worked on a system to visualize the health of our mail servers, per fifteen minute increments. This involved parsing our mail server logs. This visualization helped our team decide when we needed to call up yahoo and explain to them we aren't spammers. Send me a message (Google my name) if you want to talk about any of these concepts in greater detail.
Good luck!
-Brian J. Stinar-
this script should quee emails not to make the server down
First install a message queue like for example redis(has blocking pop), beanstalkd, gearmand. You can throttle the rate when using a message queue.
Next add message to queue from client side.
using redis for example
lpush email $youremail
and it should works on background and autumatically
Have a deamon process these messages and send email in batch with something like swiftmailer.
create a php cli file named
email.php
for exampleInside file using redis for example
blpop email
start
php email.php
as a deamon.
精彩评论