homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Sending emails to multiple users when a post is commented on
g emails to multiple users when a post is commented on

 3:48 pm on May 16, 2013 (gmt 0)

Ok, I actually write my site in ASP Classic, but ASP isnt a forum and, really, I am looking for generic logic.

I have a site with blog entries. Visitors can comment. I want to add an option for visitors to receive an email when new comments are posted. So, I guess I save the options to a table similar to:

userid blogid
100 20
101 20
102 20
105 25

Then, when blogid 20 gets a new comment, I email userids 100, 101, 102.

I am using an ASP email component and with small numbers like this, the logic is simple:
Get records from EmailWhenNewComments where blogid=20
For each record
send email

But with enough records I know this will be very inefficient. When a visitor saves a comment, it will take a long time to send all emails before returning.

What is the correct way to handle this? Does the emailing get de-coupled from the comment saving and run as a seperate process, kicked off by the save? Does the emailing logic just need to be made more efficient with something I am not aware of?

Any input would be greatly appreciated.



brotherhood of LAN

 4:07 pm on May 16, 2013 (gmt 0)

But with enough records I know this will be very inefficient. When a visitor saves a comment, it will take a long time to send all emails before returning.

I assume you are not doing the mailing process as part of the new comment submission logic, i.e. the confirmation page of the newest poster.

Create a mail queue table and run a cron job to deal with the mailing that way.


 4:25 pm on May 16, 2013 (gmt 0)

just run it every few minutes? this is a windows server so I dont think there is a cron, but should be something similar. Although it is a shared hosting server too, so not sure if I will have ability to create a timed job. I'll have to check - thanks.

brotherhood of LAN

 4:36 pm on May 16, 2013 (gmt 0)

I'd just run it every minute, but be sure that emails don't get sent out more than once, i.e. flag them as "being sent".

For Windows, not sure but if there's a control panel with your hosting, have a look at it. Windows does have a cron-type service.

If you hit a limitation of your hosting, then there's not too much you can do about that.


 8:14 pm on May 16, 2013 (gmt 0)

also, instead of sending N emails send 1 email and use a bcc: list.


 8:16 pm on May 16, 2013 (gmt 0)

I thought I read that a long BCC list is a red flag for spam blockers.


 11:31 pm on May 16, 2013 (gmt 0)

Before you do this
- do not send it to anybody who did not do an intentional, confirmed opt-in.
intentional: not forcing, no tricking, no small print, ... and not turned on by default
confirmed: make sure they act upon receiving a first "please confirm" email (it's important the recipient confirms)
opt-in: have them chose to want it.
- always add real world contact info in every email (can be a legal requirement!)
- always add a very easy opt-out: click here, no questions asked, no nothing: you're unsubscribed and will not be bothered again (don't use reply to this email: use a web page)
- make sure the text is factual, not "marketing speak"

That should keep you out of resonable anti-spam lists.

To send it out:

I'd queue them up:
- sort the recipients by domain (the part after the "@")
- then send it in bcc: to about 12 to 20 max recipients in max 3 to 5 different domains per email.
- mark the email as "bulk"
- make sure to have a working email address as sender (even if you do not read it, make sure it's accepted)

Process bounces:
- unsubscribe those that come back as undeliverable

Now that -nor anything else you do- isn't going to make you bulletproof against being flagged as a spammer.

If you can: do not send it from a hosting provider IP range. Transfer the work to a fixed IP business connection and send it from there. [they're easier to change IP addresses than they are at hosting providers- and more often than not your neighbors can be pro spammers]

The better alternative:
Or use an API to some outfit that specializes in sending bulk email. I've only ever used mailchimp, but there are others...


 3:49 am on May 17, 2013 (gmt 0)

this applies specifically to the USA but has general suggestions that apply elsewhere and echos much of what swa66 suggested.
CAN-SPAM Act: A Compliance Guide for Business | BCP Business Center:
http://www.business.ftc.gov/documents/bus61-can-spam-act-compliance-guide-business [business.ftc.gov]

if you follow the bulk email best practices and guidelines suggested by the major email providers you should be in good shape.
Mail Help | - SLN3435 - Best practices for bulk mail senders and postmasters when sending to Yahoo! Mail:
http://help.yahoo.com/kb/index?page=content&y=PROD_MAIL_ML&locale=en_US&id=SLN3435&impressions=true [help.yahoo.com]
[Microsoft] Policies, Practices, and Guidelines:
http://bay175.mail.live.com/mail/policies.aspx [bay175.mail.live.com]
Bulk Senders Guidelines - Gmail Help:
http://support.google.com/mail/answer/81126 [support.google.com]


 1:11 am on May 26, 2013 (gmt 0)

ok, it seems I have another problem. A strange one that I cant seem to find a solution to - or even someone else with the same issue.

To start, on my shared hosting I dont have access to create a scheduled process. So, the only thing I can do is send the email when someone comments on a blog post.

As I was testing this, sending emails to my yahoo account as a test was slow. If I tried to send two or three, it took about 20 seconds total. Even sending just one took 5-10 seconds. That is obviously unacceptable for some to wait that long when posting a comment on a blog. I mulled over some possible work arounds and could find none.

It occurred that I never noticed that kind of delay when I test my registration process. the only difference is that I tested that with my non-yahoo email.

It turns out, sending email from CDO to a yahoo account is VERY slow. Sending to my GoDaddy account or my work email is instantaneous.

I havent tested other account (google, hotmail) but will.

But, any idea why sending to yahoo is slow but sending to other emails is just fine?


 6:06 pm on May 26, 2013 (gmt 0)

Graylisting causes email to be intentionally slow.
It's an anti-spam feature that causes delivery of email to be fail on first try and require a retry (MTAs do that). Some spammers don't use real MTAs with queueing, retries and the like and hence their deliveries just fails.


 12:47 pm on May 27, 2013 (gmt 0)

hmmm. any way around this?

I dont want to drop a notification feature as it is so important in bringing ppl back to the site.

But if I have even one Yahoo email address to send to, the wait time is as much as 5 seconds for the form to return.

On a slightly seperate issue, I think a BCC list will not work because, then, I cant give a simple link for someone to stop following the thread (as I need the email address returned in the "unfollow link". Unless, I use cookies for that part. Unless cookies are off or the user logs in from a different PC, it should be fine. Otherwise they would need to enter the email, not that big of a deal I guess. Any thoughts?

Really the delay is far more important to me.


 12:57 pm on May 27, 2013 (gmt 0)

Since your provider doesn't offer cron services. You could ask them if they have somewhere an MTA that's willing to relay for you. That one should accept your message fast and deal with any delay itself. (MTAs are by design store and forward).

BTW: MTA: Mail Transfer Agent. E.g. sendmail

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved