hannibal Posted March 19, 2008 Share Posted March 19, 2008 Hi, I need to send a notification email to users when a new post is added. Surely I don't loop through the subscribers when a person adds a post, else that persons page would take ages to complete once their post has been submitted. Is there another way which this can be accomplished? For example, -> Create new post -> Thanks for the new post -> Loop through the MySQL table to see who needs to be notified, then email each person individually. I am sure there must be another way, but unsure of how? Does anyone have any ideas? I though about Cron jobs, but not sure if that suits? Thanks in advance, Jamie. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 19, 2008 Share Posted March 19, 2008 The best way to do this is via cron job, which is the *nix equivalent of a Windows Scheduled Task. You also want to limit the amount of e-mails you send out if you are on shared hosting, as they may limit you to x e-mails per hour. Here is what I would do. Create a PHP script that gathers up all of the subscription notifications it is supposed to send. Group these by user so that the user gets 1 e-mail with 10 notifications as opposed to 10 separate e-mails with 1 notification each. This will cut down on the amount of e-mails you actually send. Note that you don't have to do this, but I recommend it. The script should keep track of who has been notified so that it doesn't continuously notify for the same event. Finally, use cron or Windows Scheduler to run this script every 15, 30, or 60 minutes. Quote Link to comment Share on other sites More sharing options...
hannibal Posted March 19, 2008 Author Share Posted March 19, 2008 Thanks for the advice roopurt. One thing though. I have used PHPBB and other forums on a shared hosting platform which don't support Cron. How do these boards send email notifications out to many people who have subscribed to threads? Surely they must loop through when a new post is added? Thanks, Jamie. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 19, 2008 Share Posted March 19, 2008 Well, you don't have to loop through all of the existing users to find out who to send a notification to. If your database is set up correctly you should be able to run a query that grabs all the affected users and runs quite efficiently. Where this becomes inefficient is when the site is very large and very popular. Quote Link to comment Share on other sites More sharing options...
hannibal Posted March 19, 2008 Author Share Posted March 19, 2008 True. Sorry, what I meant to say was query all subscribed to x post. Then loop through the results emailing to each user individually that a new post has been added. I suppose for larger sites a Cron job really is the only way. Thanks Roop. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 19, 2008 Share Posted March 19, 2008 You don't have to e-mail individually to each one. You could send a single e-mail to the server or a junk address and BCC all of the recipients. That way none of them will know about the others. Quote Link to comment Share on other sites More sharing options...
hannibal Posted March 19, 2008 Author Share Posted March 19, 2008 Yes, for obvious reasons you would not want to see other peoples email addresses. However, an example is from this site (PHPFreaks), I get an email TO:my email address, I am not BCC'd. So therefore each user must be sent the email individually? Is this not correct? (Off topic - Also, some junk mail filters stop this method of emailing.) Thanks, Jamie. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 19, 2008 Share Posted March 19, 2008 I'm not an authority on mass e-mailing so take my advice with a grain of salt. I think when you BCC someone the e-mail will show up in their address as if it was addressed only to them. You could test this if you had more than one e-mail account. Quote Link to comment Share on other sites More sharing options...
hannibal Posted March 20, 2008 Author Share Posted March 20, 2008 roopurt18 - I have just checked and a BCC does not show up as a TO:. The original email recipient displays as the TO:. The BCC is not seen on any email. Hopefully this will clarify to people who do not know this. Looks like the only way to send an email to someone with their name in the TO: box (and no one elses) is to send individual emails. Thanksagain for your suggestions roop. Cheer, Jamie. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.