Jump to content

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 = "employee1@email.org";
$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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.