I have a web application written in php5.
The application allows users to register and I would like to delay when the various details such as password and links will be sent out. I would like the email containing this information to go 24h after a user has resisted.
How can I to execute the function that will send the email after 24 hours has passed?
It would depend on how accurate ’24’ hours needs to be, but something like the following approach should work.
Create a table to hold user registrations, or adapt an existing table to hold a
registrationTimecolumn. Make this columnnullable DATETIMEyou will use it to hold the HH:MMof the users registration. The new (or modified) table should also have the data relevant for the emails, or a common identifier for users, allowing the correct data to be selected.
Finally, you would set up a cron job to query the data base every
x minsand select the users who registered withiny minsof 24hours. Wherexis how often you want the job to run andywould be some degree of tolerance for how close to 24:00 hours had elapsed.For any results you would construct and send the emails. Finally you would set some a flag to show that user had been dealt with – a good way would be setting the
registrationTimeto null for all users who have had the email sent.Here are a few links to help you out:
Compare time in SQL Server
How can I compare time in SQL Server?
Introducing Cron
http://www.sitepoint.com/introducing-cron/