Monday April 22, 2024

Domain Expiration Notify Script

Script #2 - Notification
As I stated previously, the domain notification script is actually composed of two seperate files. Whereas the first script is to be run in CRON on an interval, the second script only runs once a day in CRON. The sole purpose of this second script is to run through all the data collected in the database created by the first script, and check for any domains that are to expire soon. It then notifies intended recipients. I chose to have notifications sent at 60 days before expiration, 30 days before expiration, 14 days before expiration, and every day from 7 days before expiration onward. This keeps the notifications from becoming too annoying, but really makes sure you don't miss a beat when it counts.

 * Domain Renewal Notifier
 * File Name: domainnotify.php
 * Author: Wayne Eggert
 * Email:
 * DESCRIPTION: Notifies a user via email when domains are
 *              coming up for renewal.
 *              Emails @ 60-days, 30-days, 14-days, and <7days
include("database.php"); // replace with your database connection include or a mysql_connect, etc of your own

// grab all the domains so we can check their expirations and status
// to determine if an email has to be sent.
$sql "SELECT domainName,registrar,expiration,status from domains WHERE DATE_ADD(expiration,INTERVAL -60 DAY) <= CURRENT_DATE()";
$result mysql_query($sql) or die(mysql_error());
$row mysql_fetch_array($result)){
$expTimestamp strtotime($row[expiration]);
$curTimestamp strtotime(date("Y-m-d",time()));
$daysLeft = (($expTimestamp-$curTimestamp)/24/60/60);

// email when 60 days are left
if($daysLeft == 60){
$sixty_days .= $row[domainName]."\n";
$sixty_days .= "Registrar: ".$row[registrar]."\n";
$sixty_days .= "Expires: ".$row[expiration]."\n\n";

// email when only 30 days are left
if($daysLeft == 30){
$thirty_days .= $row[domainName]."\n";
$thirty_days .= "Registrar: ".$row[registrar]."\n";
$thirty_days .= "Expires: ".$row[expiration]."\n\n";

// email when only 14 days are left
if($daysLeft == 14){
$fourteen_days .= $row[domainName]."\n";
$fourteen_days .= "Registrar: ".$row[registrar]."\n";
$fourteen_days .= "Expires: ".$row[expiration]."\n\n";

// email every day from 7 days before expiration
if($daysLeft <= 7){
$seven_or_less .= $row[domainName]."\n";
$seven_or_less .= "Registrar: ".$row[registrar]."\n";
$seven_or_less .= "Expires: ".$row[expiration]."\n\n";

$row[status]!='ACTIVE' && $row[status]!='REGISTRAR-LOCK' && $row[status]!='CLIENT UPDATE PROHIBITED'){
$status_change .= $row[domainName]."\n";
$status_change .= "Status: ".$row[status]."\n\n";

// compose and send email if needed
if($sixty_days != '' || $thirty_days != '' || $fourteen_days !='' || $seven_or_less != '' || $status_change != ''){
$seven_or_less != ''){

$fourteen_days != ''){

$thirty_days != ''){

$sixty_days != ''){

$status_change != ''){

$subject='Domains Are Expiring Soon! '.date("m-d-Y",time());
$headers "From: System Admin <>\r\n";
$headers .= "X-Sender: <>\r\n";
$headers .= "Content-Type: text; charset=iso-8859-1\r\n";


  • The first line is just a database include I created. Replace this with your include file or MySQL connection code.
  • The WHILE loop goes though the domains, one at a time.
  • Upon finding an issue with any of the ports being checked, the $problem variable will be set to true.
  • Finally, the script emails a notification to the user if any of the ports could not be reached.
page1 page2 page3 page4

no error but expiry date is not coming in database
Posted 03/19/11 4:26AM by leaftemp
no error all done, but no expiry date is coming in database i think this is because of wrong date format as on domain table default 0000-00-00 is different from the date format in whois server.

So please help me to correct my code.
Re: Expiration
Posted 09/21/09 6:17PM by AceBHound
Sounds like the $expiration string isn't getting built correctly. Before the SQL call to UPDATE the domains table, try echo'ing out the $expiration variable and see if it contains YEAR-MONTH-DAY (like 2009-12-31) or if it looks like "--". It's possible the WHOIS server you're using could be using a slightly different format and you'll need to adjust the code that parses out data from the WHOIS call.
Posted 09/15/09 4:52PM by Anonymous Techdoser
Great script, everything seems to work well except the expiration field in my database does not update.
Posted 08/14/09 12:21PM by thomascim
Hi Wayne, thanks very much for this useful code.

One suggestion is maybe adding an extra field to the database table for the extension.

This way you can also check domain extensions that have more or less than 3 characters like or .de, .eu, etc.

Thanks again,


problem with exec()
Posted 02/06/09 4:28PM by jschrader
I have installed the code, and am getting an error about the exec(), to be specific:

Warning: exec() has been disabled for security reasons in /home/a5704353/public_html/notify.php on line 38

Free Web Hosting

PHP Error Message

Warning: Invalid argument supplied for foreach() in /home/a5704353/public_html/notify.php on line 39

what is going on?
how to get the registrar
Posted 06/03/07 3:40PM by rocko
Hi, I see your script. It is really good and help me a lot.
But Im trying to use a registrar field. I use different string functions but I couldn't.
There are any way to use the registrar field?
Thanks in advance.
How to set cron tab
Posted 10/16/06 12:01AM by creativetest
How to set cron tab