Here's the code I was using. It is set up to send emails at 10 and 5 and 1 days from expiration. Again, I'm not using Ryans version so you may have to modifiy it.
Code:
function listings_expiration() { //email sellers about listings expiring
global $conn, $lang, $config, $style;
$sql="SELECT user_ID,a.ID,emailAddress,expiration,
TO_DAYS(expiration)-TO_DAYS(NOW()) as Days
FROM listingsDB a, UserDB b
where (TO_DAYS(expiration)-TO_DAYS(NOW())=10 or TO_DAYS(expiration)-TO_DAYS(NOW())=5
or TO_DAYS(expiration)-TO_DAYS(NOW())=1 or
TO_DAYS(expiration)-TO_DAYS(NOW())<=0)
and user_ID = b.ID";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) log_error($sql);
$num_recs = $recordSet->RecordCount();
if ($num_recs > 0)
{
// return the email address
while (!$recordSet->EOF)
{
$user_ID = make_db_unsafe ($recordSet->fields[user_ID]);
$listingID = make_db_unsafe ($recordSet->fields[ID]);
$email = make_db_unsafe($recordSet->fields[emailAddress]);
$formatted_expiration = $recordSet->UserTimeStamp($recordSet->fields[expiration],'M j, Y');
$days_expired = make_db_unsafe($recordSet->fields[Days]);
if ($days_expired= 5 || $days_expired=10||$days_expired=1) {
$message= "Your listing, Ad# $listingID, on Home 2 Sell is going to expire in $days_expired day(s) on $formatted_expiration.\r\n
Click the following link to see the listing:\r\n$config[baseurl]/listingview/$listingID\r\n\r\n
Click the following link to log-in and go to edit my listings to renew your listing:\r\n$config[baseurl]/index.php";
} else {
if ($days_expired <=0) {
$message= "Your listing, Ad# $listingID, on Home 2 Sell has expired.\r\n
If it is not renewed in 14 days, it will be deleted from our system.\r\n
If your listing has sold, please update the status of your listing to sold.
Click the following link and log-in and go to edit my listings to renew your listing or update the status:\r\n$config[baseurl]/index.php";
}
//}
$message = stripslashes($message);
$subject = "Listing Expiration on Home 2 Sell";
$recordSet->MoveNext();
mail("$email", "$subject", $message,"From: $config[admin_email]", "-f$config[admin_email]");
// ta da! we're done...
log_action ("$lang[log_mailed_listing] $listingID");
}//end while
}else {
log_action("$lang[log_zero_mailed] $listingID");
exit();
} //end if
}//end listing expiration
Instead of using "if ($days_expired= 5 || $days_expired=10||$days_expired=1) ", you could also use "if ($days_expired >0)".
Bookmarks