Jump to content

Setting up an e-mail reminder, comparing dates


kahodges

Recommended Posts

I'm trying to set up an e-mail notification as a reminder to let me know when a vehicle inspection is due, preferably a month in advance. When a date is one month prior to the date in the due_date inspection table, it should send the reminder. Your help would be greatly appreciated. I'm not sure how to code it to check the date and compare it to a date one month from now. I'm also not sure if I have the database schema set up correctly for the dates. I figure I could run a cron job once a day to run the script and to pull the reminder. Below is the php code and MySQL schema I have so far:

 

<?php 
//calling PEAR Mailer 
require_once "Mail.php"; 
?>
//connect to the database 
<?php function connect() 
{ 
  require('includes/config.php'); 
  return $conn; 
} 
?> 
<?php 
// Make a MySQL query 
$query = "SELECT * FROM inspection"; 
$result = mysql_query($query) or die(mysql_error()); 
$row = mysql_fetch_array($result) or die(mysql_error()); 
$from = "Server Database <[email protected]>"; 
$to = "me <[email protected]>"; 
//$cc = "another person <[email protected]>"; 
$subject = "Vehicle Inspection Reminder"; 
$body = "echo "The following vehicle is due for inspection:; 
echo $row['vehicle']; 
if (!$conn) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 

?>"; 

$host = "mail.server.com"; 
$username = "username"; 
$password = "password"; 

$headers = array ('From' => $from, 
  'To' => $to, 
  'CC' => $cc, 
  'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
  array ('host' => $host, 
    'auth' => true, 
    'username' => $username, 
    'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
  echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
  echo("<p>Message successfully sent!</p>"); 
} 
?>

 

MySQL schema:

 

`CREATE TABLE IF NOT EXISTS `inspection` ( 
  `id` int(6) NOT NULL AUTO_INCREMENT, 
  `vehicle` varchar(10) COLLATE utf8_unicode_ci NOT NULL, 
  `last_date` varchar(10) COLLATE utf8_unicode_ci NOT NULL, 
  `due_date` varchar(10) COLLATE utf8_unicode_ci NOT NULL, 
  PRIMARY KEY (`id`), 
  KEY `vehicle` (`vehicle`,`last_date`,`due_date`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;` 

 

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.