2

I am currently working on a project that requires sending email notifications to users. The way it works, users follow certain catergories of posts/group, whenever there is a new post or comment under the post category/group they get email message notifying them with a snippet of the post itself.

I am expecting to send upwards of 5000 emails daily. Is it effective to use cron job to fetch users and send the emails at intervals or is there a better means to push this email while avoiding blacklisting on my IP by email providers.

Below is my table structure

First Table

Notification
ID // autoincrement
message // the message sent to users
createDate // date created

Second Table

User_Notification
ID // auto increment
userid // Id of users
notification_id // id of notification from first table
status // 0 or 1 

So whenever a post is added, I insert the notification in the first table (notification) and then fetch all followers of that group from another table (following) where i store userids and the group ids. I then insert for each user in the second table (user_notification).

My cron job fetchs like 20 records from user_notification table and also fetch the notification message from notification table. I also fetch user email from my user table.

$firstquery = $lnk->mysqli->query("select * from user_notification where status=0 order by id ASC limit 0, 20", MYSQLI_USE_RESULT);
$secondquery = $lnk->mysqli->query("select * from notification where id=$notification_id", MYSQLI_USE_RESULT);
$thirdquery = $lnk->mysqli->query("select email from user_table where id IN($userids)", MYSQLI_USE_RESULT);

for($no=0;$no<counter;$no++)// loop to send emails
{
$lnk->emailsender($subject,$emailbody,$usr_email[$no]);
}

Please is there any better way to do this?

5
  • 2
    blacklisting by isp doesn't really matter if you send them at intervals or not. we tried this, our isp firstly blocked them as they thought we had been hacked, upon unblocking this and refusing to do so we then had problems with our DNS server host as they said it would slow up the DNS servers with the amount of queries being made through DNS. We also weighed up the options and then realised that it was better to use a 3rd party who already has a white listed ip address and is built for these sorts of applications Commented Aug 7, 2013 at 15:49
  • you are so going to be blacklisted unless you use something else to send your emails. Try using sendgrid is really easy to use, and is not so expensive. sendgrid.com/docs/Code_Examples/php.html Commented Aug 8, 2013 at 4:02
  • 1
    @dvidsilva Thanks for your suggestion am currently considering mandrill.com giving their pay as you go option quite cheaper than sendgrid. Commented Aug 8, 2013 at 13:14
  • @andychukse ok, it is a good option i have't checked the different pricing things coz unfortunately i have never went over 10 daily emails :P Commented Aug 8, 2013 at 17:27
  • I know it's late but www.mailingmanager.co.uk/ Is cheap and good we get around 80,000 emails a month for about £80 a month but I think it's 10 for every 10,000 emails Commented Aug 8, 2013 at 19:55

2 Answers 2

2

Unless you have a very specific relationship with your ISP, it is extremly likely you will be blacklisted, or your e-mails will go straight to spam. It is difficult to establish mass e-mails as legitimate. You can use a mass mailing services API to do some of the dirty work for you, like mail chimp or constant contact.

So the code you have will most likely work, minus e-mailing bit which should be done via a mailing service and their associated API.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I'm going for mandrill.com (owned by mailchimp). I appreciate your candid advice.
1

5000 emails a day is roughly 4 emails per minute, or one email every 15 seconds. If I were you I would write a cron routine to run every minute that will send the emails which are due to be sent. This will ensure you avoid being treated like a spammer for sending out 2500 emails quickly, for example. It also means your users get email notifications quickly.

You could also send out the emails as soon as a user gets a notification, bypassing the need for a cron routine however if your site hits a surge in activity for whatever reason you could find some emails don't get through.

You could also consider using a 3rd party service like MailChimp which already has good authority with email providers, however that comes at a price and for 4 emails a minute I wouldn't consider it worthwhile.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.