EMAIL REMINDER AGAIN lol SOZ

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nachoman316
Forum Newbie
Posts: 12
Joined: Sat Apr 11, 2009 6:40 am

EMAIL REMINDER AGAIN lol SOZ

Post 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;
}
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: EMAIL REMINDER AGAIN lol SOZ

Post 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);
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: EMAIL REMINDER AGAIN lol SOZ

Post 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
}
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: EMAIL REMINDER AGAIN lol SOZ

Post 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.
Post Reply