SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Help with E-mailing Distribution List

    So I just created a way for Members to "subscribe" to an Article so they get updates whenever other Members add a Comment.

    Now I need to build the code that actually notifies them that a new Comment was added.

    What I am wondering about is this...

    What is the best way to take a series of E-mails from an MySQL Query and get it into an E-mail notifying everyone that subscribed to that Article that a new Comment was posted?

    1.) I am not sure how to physically get the database query result-set into the mail() function/program.

    2.) I suppose I need to be extra careful of people's privacy, and even if I am e-mailing 20 people, each recipient should think the notification is *only* coming to them, and they should NOT be able to see other Members' E-mails!!!

    Can someone help get me started on this?

    Thanks,


    Debbie

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,052
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Legitimate providers of shared servers do not tolerate sending mass email notifications. Unless you plan on running a dedicated server the best option is to use a third party service to actually dispatch the emails on your sites behalf. The implementation would of course change based on the provider chosen. Now this isn't to say you *can't dispatch the emails on your sites servers but don't be surprised if you get shut down for spam. Consider this a warning…
    The only code I hate more than my own is everyone else's.

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    Legitimate providers of shared servers do not tolerate sending mass email notifications. Unless you plan on running a dedicated server the best option is to use a third party service to actually dispatch the emails on your sites behalf. The implementation would of course change based on the provider chosen. Now this isn't to say you *can't dispatch the emails on your sites servers but don't be surprised if you get shut down for spam. Consider this a warning…
    Now that you are done "warning" me, realize that I have my own VPS...


    Debbie

  4. #4
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    That's not completely true. Most shared hosts forbid spamming ... but not necessarily mass emails. In fact, most cPanel shared hosting plans come with mailing list software in the cPanel itself. What many of them DO limit, however, is the number of emails you can send per hour (which is different in most cases to the number of email addresses per email).

    Anyway, moving forward.

    There are two ways you can prevent others from seeing all the email addresses. One would be to send an individual email for each subscribed user but that can be very inefficient. Especially if you have many users subscribed to a thread. The second option would be to put all the subscribers' emails in the BCC field instead of the standard TO field.

    As for getting the list of subscribed users ... one good option may be to have a separate "subscribed threads" table with a column for the user, and a column for the thread. That way you can simply do a SELECT for all users subscribed to "the thread that was just updated", and feed the list of emails into your code that builds/sends the email.

    You probably don't have to worry much about email limits being on a VPS, but you still may want to think about email queueing/throttling, if for any reason for performance. Especially if there's a potential for a lot of subscribers, and/or a lot of thread updates.

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,052
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Now that you are done "warning" me, realize that I have my own VPS...


    Debbie
    fair enough
    The only code I hate more than my own is everyone else's.

  6. #6
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kduv View Post
    That's not completely true. Most shared hosts forbid spamming ... but not necessarily mass emails. In fact, most cPanel shared hosting plans come with mailing list software in the cPanel itself. What many of them DO limit, however, is the number of emails you can send per hour (which is different in most cases to the number of email addresses per email).
    Last time I checked, GoDaddy had no issues, other than I may have to pay a little more for the extra use of there servers.



    Anyway, moving forward.

    There are two ways you can prevent others from seeing all the email addresses. One would be to send an individual email for each subscribed user but that can be very inefficient. Especially if you have many users subscribed to a thread. The second option would be to put all the subscribers' emails in the BCC field instead of the standard TO field.
    After I made my post, I came up with this solution in pseudo-code only...

    - When a User posts a Comment I call my notifySusbcriptionList() function.

    - I pass the function the articleID and memberID (for the person making the Comment)

    My function...
    - Casts the arguments to Integer
    - Runs a Prepared Statement to check if the articleID is found
    - Runs a Prepared Statement to check if the memberID is found
    - If arguments are found...
    - Runs a Prepared Statement to find all Members in the "subscription" table
    - Retrieve records

    (The part I wasn't sure about...)
    - Loop through each record (Email) in the recordset
    - Send an e-mail to each email like this...

    Re: New Comment to "Postage Meters can save you Money"

    Dear Debbie,

    For the article "Postage Meters Can Save You Money", the member, "luvTheOutdoors123", has posted a new comment.

    To view the article click here.

    To view the comment go here.

    Doing that would mean ONE E-mail for ONE Member, so I wouldn't have to worry about spilling my entire Subscription List to others.

    I suppose that if my website was a successful as SitePoint, then that might require a dedicated E-mail Server, but I think that is a ways down the road considering my static v1.0 website gets maybe 15 visitors per week!!!


    As for getting the list of subscribed users ... one good option may be to have a separate "subscribed threads" table with a column for the user, and a column for the thread. That way you can simply do a SELECT for all users subscribed to "the thread that was just updated", and feed the list of emails into your code that builds/sends the email.
    Yep, I already built that.

    It looks like this...

    Code:
    - id
    - article_id
    - member_id
    - subscribed_on
    - unsubscribed_on

    You probably don't have to worry much about email limits being on a VPS, but you still may want to think about email queueing/throttling, if for any reason for performance. Especially if there's a potential for a lot of subscribers, and/or a lot of thread updates.
    What do you mean by "E-mail Queuing" and "E-mail Throttling"?

    Thanks,


    Debbie

  7. #7
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Queuing/throttling basically just means sending out notifications in batches instead of all of them immediately. You probably won't have to worry about it unless your site gets fairly busy, but I personally like to make sure my apps will scale for the future. Besides, it's much easier to build a queuing system in the beginning as opposed to having to go back in a few months later and re-writing everything.

    It could look something like this...
    Instead of immediately sending the notification email to subscribed users when a thread is updated, just add the relevant information into an email_queue table or where ever.
    Then set up a cron job that runs every 10 minutes or so that checks to see if there are any pending emails in that table that need to be sent. If so, send out 10 or 20, and remove those records from the table.

    That way if you get busy, your server isn't sending out a constant stream of emails just a batch at a time. Not only can it help with performance, but it can greatly reduce the chance of other external mailservers thinking that you're sending out mass spam. You definitely don't want to have your server added to any of the big blacklists. It can be a pain to get your server off of one.

  8. #8
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    You may want to look at the Swift Mailer which is a completely open source robust RFC compliant mailer library with great online documentation. One benefit of this library based on the advise you've been given is that you can queue and throttle email without having to roll your own code. It also in the documentation provides examples of how to use when a database (MySQL) result set is used.

    When it comes to being banned as an email domain it does not mean that you are safe by serving your site on a dedicated VPS. If enough (even a few) people complain to your host that you are spamming then the ISP may be forced to block your domain, and often they will not issue you another fixed I.P. for the same domain. If you have not done so, you need to ensure that you closely read the fine print of the terms and conditions for your provider as they will often explain what will happen if you become reported.

    Some ISP (as previously mentioned) come with bulk email services that you can pay for and implement via 'their' process. This is often a better way to do it as then they fight any reports as they need to provide you, the paying customer for bulk email, the service.

    Steve
    ictus==""

  9. #9
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    You may want to look at the Swift Mailer which is a completely open source robust RFC compliant mailer library with great online documentation. One benefit of this library based on the advise you've been given is that you can queue and throttle email without having to roll your own code. It also in the documentation provides examples of how to use when a database (MySQL) result set is used.
    I had someone else mention this app for security reasons.

    I'll have to try and read up on it.


    When it comes to being banned as an email domain it does not mean that you are safe by serving your site on a dedicated VPS. If enough (even a few) people complain to your host that you are spamming then the ISP may be forced to block your domain, and often they will not issue you another fixed I.P. for the same domain. If you have not done so, you need to ensure that you closely read the fine print of the terms and conditions for your provider as they will often explain what will happen if you become reported.
    Again, the purpose of these e-mails is to notify people who "subscribe" to a thread that new Comments have been posted. (Just like SitePoint offers.)

    Do you really think that could be an issue when people have to sign up to be notified? (I am NOT soliciting anyone for anything. Just saying, "Hey, someone else made a comment to the article you are following."


    Some ISP (as previously mentioned) come with bulk email services that you can pay for and implement via 'their' process. This is often a better way to do it as then they fight any reports as they need to provide you, the paying customer for bulk email, the service.

    Steve
    As a rule-of-thumb, how would that affect my script's code?

    Right now I call a notifyArticleSubscribersOfNewComment() function from my "add_comment.php" script and I loop through everyone who "subscribed" and thus is in my "subscription" table. (People can "un-subscribe" at any time.)

    Thanks,


    Debbie

  10. #10
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Again, the purpose of these e-mails is to notify people who "subscribe" to a thread that new Comments have been posted. (Just like SitePoint offers.)

    Do you really think that could be an issue when people have to sign up to be notified? (I am NOT soliciting anyone for anything. Just saying, "Hey, someone else made a comment to the article you are following."
    Yes this still can be a issue. I have seen many smaller website that have subscription and one of their subscribe members claims that you spammed them. Sometimes people don't remember where they signed-up, some people 'pull the trigger and ask questions later' and some people understand the process and don't cause any trouble.

    With the volume of people that you currently have, this may not be an issue for a while; however it can quickly become the case when the popularity of the site grows.
    [/quote]

    Quote Originally Posted by DoubleDee View Post
    As a rule-of-thumb, how would that affect my script's code?


    Generally the ISP provides and API to their bulk email service that enables you to authenticate (to show your a valid bulk user) and then send email via that part of their service.
    ictus==""

  11. #11
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,531
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Yes this still can be a issue. I have seen many smaller website that have subscription and one of their subscribe members claims that you spammed them. Sometimes people don't remember where they signed-up, some people 'pull the trigger and ask questions later' and some people understand the process and don't cause any trouble.

    With the volume of people that you currently have, this may not be an issue for a while; however it can quickly become the case when the popularity of the site grows.


    Generally the ISP provides and API to their bulk email service that enables you to authenticate (to show your a valid bulk user) and then send email via that part of their service.
    Thanks for the "heads up"!

    I'll have to see what my options are with GoDaddy or whoever I host with in the future.


    Debbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •