Search the Community
Showing results for tags 'email php mysql'.
-
I have the following code and i know im close but dont have it right. Im trying to setup a cron job to run and pull messages from a database every hour. Here is the code so far. <?php $con = mysql_connect(mine","myuser","mypass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); Need $time setup $today = date("Y-m-d"); I need the query to select the data where i have 3 columns for the date Year-Month_Day and compare it to $today as well as the time Time and Time2. Time holds the time in 12 hr format and time2 holds AM/PM. $result = mysql_query("SELECT * FROM table where Year-Month-Day >= '$today'"); I think the below is correct. What should happen is.... The script should see if the database has any messages that need to be sent today then depending on the hour send those messages to the person. I want the cron job to run hourly to do this. Reason for this is the person creating the messages is able to decide what time they want the message delivered. The closest thing i can compare it to is a alarm clock. sending a message to the email address at a certain time on a certain date. Hope that helps while ($row = mysql_fetch_array($result)) { { $email=$row['emailid']; $to = $EmailAddress; $subject = "You have a Message on mysite.com from $Name"; $body = "$Message"; $headers = 'From: Message@mysite.com' . "\r\n" ; $headers .= 'Reply-To: Message@mysite.com' . "\r\n"; mail($to, $subject, $body, $headers); } mysql_close($con); ?>