cdoggg94 Posted June 7, 2013 Share Posted June 7, 2013 I would like to set up a reminder system where on a certain day of the users choice, they are sent an email to remind them of a specific thing. What I have now is a "To Do" list. here: <?php $today = date("m.d.y"); ?> <table border="0"> <tr> <td align="center"> <span style="font-size:14px;"><?php echo $today2; ?></span><br /><br /> </td> </tr> <tr> <td> <span style="font-size:14px; font-weight:bold;">To Do List:</span> <ul> <?php do{ ?> <li> <?php echo $row_toDO['toDo_info'] ;?> <br /><a href="index.php?toDo_id=<?php echo $row_toDO['toDo_id']; ?>">Delete</a><br /><br /> </li> <?php } while ($row_toDO = mysql_fetch_assoc($toDO)); ?> </ul> </td> </tr> </table> You add things to this list with this form: <table border="0" align="center"> <tr> <td align="center" style=" font-size:14px;">Add to To Do List</td> </tr> <form action="<?php echo $editFormAction; ?>" method="POST" id="toDo" name="toDo"> <tr> <td align="center"><textarea name="info" cols="26" rows="5"></textarea> </td> </tr> <tr> <td align="center"> <input name="id" type="hidden" value="" /> <input name="user" type="hidden" value="Dave" /> <input type="submit" value="" class="imgClass3" /> </td> <input type="hidden" name="MM_insert" value="toDo" /> </tr> </form> </table> My idea is to add a date section to the form, so that if they would like to be reminded on say "June 10, 2013" They select June, 13, 2013...etc..Now...my issue now is: Where would I make a script to ensure they get this reminder even if you are not using a specific page? My thought process is telling me that the script structure should be something like, if (toDoDate == todaysDate) { email reminder } Am I even close here ? Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/ Share on other sites More sharing options...
trq Posted June 7, 2013 Share Posted June 7, 2013 No. You would set up a cronjob on the server to execute daily, check the database for reminders and send emails whenever required. Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434648 Share on other sites More sharing options...
DaveyK Posted June 7, 2013 Share Posted June 7, 2013 If you would follow your logic, the email would only be sent if you load the page, which is not really the best. I dont need a reminder if I am already viewing the reminders. Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434652 Share on other sites More sharing options...
trq Posted June 7, 2013 Share Posted June 7, 2013 If you would follow your logic, the email would only be sent if you load the page, which is not really the best. I dont need a reminder if I am already viewing the reminders. I'm sure he meant the system would check for *all reminders* anytime anyone viewed *any page*. This can kinda be used to executed events at given intervals if you have a reliable source of traffic. Really though, it's not at all reliable. Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434653 Share on other sites More sharing options...
DaveyK Posted June 7, 2013 Share Posted June 7, 2013 I'm sure he meant the system would check for *all reminders* anytime anyone viewed *any page*. This can kinda be used to executed events at given intervals if you have a reliable source of traffic. Really though, it's not at all reliable. Sure, I get that, but that its still no guarentee you will actually get reminded, as you also point out. Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434655 Share on other sites More sharing options...
cdoggg94 Posted June 7, 2013 Author Share Posted June 7, 2013 I am still not 100% sure where to put the Cron Job. If say the "To Do" list is on the index page, would I be adding the script to that page ? I am looking at this right now : http://www.thesitewizard.com/general/set-cron-job.shtml and it it showing me basic format, but I am still a little confused as how to use it.Does anyone know of a better example link? Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434660 Share on other sites More sharing options...
cdoggg94 Posted June 7, 2013 Author Share Posted June 7, 2013 And say the user wanted this reminder on "june 10, 2013, 9:30am".Is this what I would put? 30 9 6 10or would I check on the hour until the specified date/time happened ? Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434661 Share on other sites More sharing options...
DaveyK Posted June 7, 2013 Share Posted June 7, 2013 Well, you can set up the cronjob to run, say, once a day for now, and it gives the user an overview of the reminders he has today. You shouldnt adapt the cronjob to the user. Just embrace the fact that you cant get it right on the minute, or even on the hour. Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434701 Share on other sites More sharing options...
cpd Posted June 7, 2013 Share Posted June 7, 2013 (edited) Just embrace the fact that you cant get it right on the minute, or even on the hour. Not true. You can set the cronjob to run every hour if you wanted. If you have lots of reminders then its obviously going to take longer with just a single server, but you can still do it. Think of google calendar (I'm not saying they use a cron but its a similar concept), they dispatch reminders to the minute and may use a cluster server for carrying out the task. Crontab is a program used to set up new cronjobs that are executed by the cron daemon on a linux machine (usually a server else the whole concept would be pretty pointless as normal computers are turned off regularly). What it executes is entirely up to you; you could execute a python script if you wanted, not just php. In your case you're going to be executing a PHP script that connects to a database, retrieves all the reminders for a given day, and sends an email to the user with a list of events. You could trigger the cron to go off in the early hours of the morning every day: 0 4 * * * php /home/account/private/crons/dispatchReminders.php For a guide on the crontab and how to use it you can go to http://crontab.org/. The tutorial you already have simplifies it quite a bit and abstracts the main content. The script you execute is completely separate from the script you use to display the reminders as they have two separate purposes. One is to dispatch reminders, the other is to display reminders to an end user using HTML in a web browser (just an example). Edited June 7, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434714 Share on other sites More sharing options...
DaveyK Posted June 8, 2013 Share Posted June 8, 2013 (edited) I get that you can set a cronjob every hour if you see that interval fit. I was merely trying to explain that setting a cronjob on a specific time set by the user is not the way that is supposed to work and I was indeed a little short sighted in not mentioning that every hour is an option, but you wont get it down to the minute. You COULD set it to the minute, but the smaller the interval is the bigger the server is you will need. Google calendar can easily support a minute support, simply because Google is Google. Thanks for pointing that out though. Edited June 8, 2013 by DaveyK Quote Link to comment https://forums.phpfreaks.com/topic/278891-reminder-system/#findComment-1434852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.