Page 1 of 1

EMAIL REMINDER AGAIN lol SOZ

Posted: Sun Jun 21, 2009 10:12 am
by nachoman316
Hello again guys and sorry to be repeating my self a little here but im having trouble writing the code for an email reminder script.

Basically users input their email addresses into a form inserting them into a database.

Then two days before an event (classical music event) they will be sent out an email reminder.

My main problem is that I dont know how to write a query that tells the script to send the email 2 days before the event.

Any examples would be greatly appreciated.

ie: if(todayDate < 2days before ProgrammeDate){
send email
}else{
exit;
}

Re: EMAIL REMINDER AGAIN lol SOZ

Posted: Sun Jun 21, 2009 2:07 pm
by Eric!
Depends on how you are storing the event date data in your database. What does your date/time field look like? 2009-5-22?

You can make mysql do the work:
SELECT *
FROM yourtable
WHERE EventDate = '$future'

Just search for events 2 days away.

Code: Select all

$future  = mktime (0,0,0,date("m") ,date("d")+2,date("Y"));  
$future= date("Y-m-d", $future);

Re: EMAIL REMINDER AGAIN lol SOZ

Posted: Sun Jun 21, 2009 5:40 pm
by jayshields

Code: Select all

SELECT
  `email`
FROM
  `table`
WHERE
  `event_date` < NOW() + INTERVAL 2 DAY
AND
  `event_date` > NOW()
Then...

Code: Select all

foreach(email in resultset)
{
  send an email
}

Re: EMAIL REMINDER AGAIN lol SOZ

Posted: Mon Jun 22, 2009 8:49 am
by Eric!
One thing about Jay's solution is your eventdate field needs to be in the datetime format ('2007-12-15 23:50:26') and it will do an exact time check, so if you run your email script at noon, it won't send out notices for events occuring in the evening two days from now because it is over 48 hours. You would need to run this script more often and keep track of who has been notified already, or which events you've already sent out announcements for to avoid duplicates.