Guest Posted March 29, 2011 Share Posted March 29, 2011 The following code looks at my MySQL database at the due_owner field. This is a date field & if the due_owner date is less within 6 days of the current date, it sends an email to the $email variable. This code works great! The only issue I have is, is there ANY way for me to adjust this code so it will stop sending emails after the date listed in the due_owner field? At this time, the email address listed in teh $email variable still gets an email after the date in the due_owner field. If this is not possible, is it possible to adjust the code so it will only send the email one time? I have this code as part of a script that runs each night at midnight...Thanks <?php include('connection.php'); $number_of_days_before = 6; $email = "[email protected]"; $reminder_details = ""; $todays_date = date( "Ymd" ); echo $todays_date; $year = substr($todays_date, 0, 4); $month = substr($todays_date, 4, 2); $date = substr($todays_date, 6, 2); $trigger_date = date("Ymd", mktime(0,0,0,$month, $date-$number_of_days_before,$year)); echo $trigger_date; $result = mysql_query( "SELECT due_owner, employee, pacts, dock, name, lname FROM psrinfo WHERE employee='Jane Doe' AND due_owner <= $trigger_date" ); $nr = mysql_num_rows( $result ); while( $row = mysql_fetch_array( $result ) ) { $reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n"; $reminder_details .= "PACTS Number: ".$row["pacts"]."\n"; $reminder_details .= "Dock: ".$row["dock"]."\n"; $reminder_details .= "Due to Owner: ".$row["due_owner"]."\n\n\n"; } mysql_free_result( $result ); if( !empty( $nr ) ) { $mailheader = "From: The Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain"; mail("$email", "Due to Within 6 Days", "$reminder_details", "$mailheader"); } ?> Link to comment https://forums.phpfreaks.com/topic/232090-php-code-help-needed/ Share on other sites More sharing options...
ignace Posted March 29, 2011 Share Posted March 29, 2011 $trigger_date BETWEEN due_owner - INTERVAL 6 DAY AND due_owner Link to comment https://forums.phpfreaks.com/topic/232090-php-code-help-needed/#findComment-1193828 Share on other sites More sharing options...
Guest Posted March 29, 2011 Share Posted March 29, 2011 Do I add that to the query as so: $result = mysql_query( "SELECT due_owner, employee, pacts, dock, name, lname FROM psrinfo WHERE employee='Jane Doe' AND due_owner $trigger_date BETWEEN due_owner - INTERVAL 6 DAY AND due_owner" ); Link to comment https://forums.phpfreaks.com/topic/232090-php-code-help-needed/#findComment-1193842 Share on other sites More sharing options...
ignace Posted March 30, 2011 Share Posted March 30, 2011 As so: $result = mysql_query( "SELECT due_owner, employee, pacts, dock, name, lname FROM psrinfo WHERE employee='Jane Doe' AND $trigger_date BETWEEN due_owner - INTERVAL 6 DAY AND due_owner" ); Link to comment https://forums.phpfreaks.com/topic/232090-php-code-help-needed/#findComment-1194134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.