Jump to content

PHP Code Help Needed


Guest

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.