Get Notified of 404 Errors

One addition I have found useful is to add email notification when my custom 404 page is invoked. Since I use a PHP file for the custom 404 adding email notification is pretty easy. I renamed the original custom404.htm to custom404.php then added the email code.

The email sent will spell out the invalid page that caused the 404 error. BTW, 404 is the error generated by HTTP when an invalid or nonexistent web page is trying to be accessed. The commented out echo code was used for diagnostics.

Note that nothing is shown on the custom 404 page. The email occurs behind the scenes.

Here is the code:


<?php
// send error email
$em = "someone";
$em .= "@";
$em .= "mydomainname";
$em .= ".com";

$subject="Custom404";
$message="A custom 404 page was accessed from mysecurepc site";
$message .= " The page accessed was: " . $_SERVER['REDIRECT_SCRIPT_URI'];

if(mail("$em","$subject","$message","From: $em")){
//echo "e-mail sent !!!";
}else{
//echo "error !!!";
}
?>

A few things I have noticed since I set this up on a couple of web sites for testing.

1. For some reason, I get a custom 404 email when a bookmark like

...domain.com/folder/webpage.html#topofpage

is accessed. I have not been able figure out why, yet.

2. If you do not have a favicon.ico then the custom 404 page is invoked and you will get email. This occurs when IE accesses the home page.

3. Deleted web pages may show up in an 404 email since search engines retain these links for a while. The searchbots invoke these.

4. Deleted or name-changed web pages may show up because someone is using an old link.

Overall it has given me valuable feedback despite some unwanted emails.

Doug

Leave a Reply

You must be logged in to post a comment.