Jump to content

Notify subscribers on new post


hannibal

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.