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?