- Thu Apr 27, 2023 2:54 pm
#830550
you can try this
// Get the current date
$currentDate = date('Y-m-d');
// Get the expiry date for vehicles that will expire in two weeks
$twoWeeksExpiryDate = date('Y-m-d', strtotime('+2 weeks'));
// Get the expiry date for vehicles that will expire in one week
$oneWeekExpiryDate = date('Y-m-d', strtotime('+1 week'));
// Get the expiry date for vehicles that will expire today
$expiryDate = $currentDate;
// Get a list of vehicles that will expire in two weeks
$twoWeeksExpiryVehicles = executeQuery("SELECT * FROM vehicles WHERE expiry_date = '{$twoWeeksExpiryDate}'");
// Get a list of vehicles that will expire in one week
$oneWeekExpiryVehicles = executeQuery("SELECT * FROM vehicles WHERE expiry_date = '{$oneWeekExpiryDate}'");
// Get a list of vehicles that will expire today
$expiryVehicles = executeQuery("SELECT * FROM vehicles WHERE expiry_date = '{$expiryDate}'");
// Send notifications for vehicles that will expire in two weeks
foreach ($twoWeeksExpiryVehicles as $vehicle) {
$message = "Hello {$vehicle['user_name']},\n\nYour vehicle with the registration number {$vehicle['registration_number']} will expire in two weeks on {$vehicle['expiry_date']}. Please renew your vehicle registration before the expiry date.\n\nThank you.";
PMFSendMessage(@@APPLICATION, 'admin@example.com', $vehicle['user_email'], '', '', 'Vehicle Expiry Notification', $message);
}
// Send notifications for vehicles that will expire in one week
foreach ($oneWeekExpiryVehicles as $vehicle) {
$message = "Hello {$vehicle['user_name']},\n\nYour vehicle with the registration number {$vehicle['registration_number']} will expire in one week on {$vehicle['expiry_date']}. Please renew your vehicle registration before the expiry date.\n\nThank you.";
PMFSendMessage(@@APPLICATION, 'admin@example.com', $vehicle['user_email'], '', '', 'Vehicle Expiry Notification', $message);
}
// Send notifications for vehicles that will expire today
foreach ($expiryVehicles as $vehicle) {
$message = "Hello {$vehicle['user_name']},\n\nYour vehicle with the registration number {$vehicle['registration_number']} will expire today on {$vehicle['expiry_date']}. Please renew your vehicle registration as soon as possible.\n\nThank you.";
PMFSendMessage(@@APPLICATION, 'admin@example.com', $vehicle['user_email'], '', '', 'Vehicle Expiry Notification', $message);
}
Replace vehicles with the actual name of your database table that contains the vehicle expiry date and user information.
Finally, you can schedule this script to run on a daily basis using a cron job