You'll want to separate the system into two applications:
- The application users use to schedule things.
- The back-end application that sends the emails.
The first application should write the scheduled items to a database and the back-end application would read from the database and send the emails.
One way you may be able to structure this is to have the scheduled items stored something like this:
ScheduledItems
--------------
ID (int)
Title (string)
EventTime (datetime)
ReminderType (int)
ReminderSent (bool)
The ReminderType
might be a foreign key to a lookup list of the reminders you mentioned:
5m, 10m, 30m, 1h, 2h, 5h, 12h, 1d and 2d before the event starts
The second application would then be scheduled via cron to run probably every 5 minutes (since that's the most granular reminder time) and scan for ScheduledItems
where ReminderSent
is false (hasn't been sent yet) and EventTime
minus some timespan value in the ReminderType
lookup table is less than or equal to the current datetime.
For each record it finds, send the reminder and update ReminderSent
to true.