get referring pages for 404 mail to webmaster

Posted on 2011-09-19
Last Modified: 2012-05-12
is there any way to make a 404 page that can email to a specific address the page the user was trying to reach when he or she got the 404.  The examples I've seen online just print out 404.php when they try to email where the user came from, which is not very useful. I've tried working with javascript referrers (but they seem only to work if a link is pressed, not something mis-typed or given to the user incorrectly), and some php $_SERVER inquires, but i can't seem to get it to work..

Grateful for any ideas!
Thank you.
Question by:hibbsusan
  • 7
  • 4
LVL 21

Accepted Solution

Hendrik Wiese earned 500 total points
ID: 36559127

Please refer to the following link to setup a 404 page that emails:

Author Comment

ID: 36569730
for me, this just shows the 404.php file as the url that access was attempted on.  can't i get the site that the user typed in?


Author Comment

ID: 36569822
my last post was worded poorly.

In the email I receive from this script, I would like to see what url the user tried to load.

for example: user wants to see the page with images, so he types:

and he gets a 404 because the url that has images is actually located at:

in the email I receive i would like to see:
"User got a 404 when he tried to go here:"

But with this program, I see:
"User got a 404 when he tried to go here:"

well, or course that's not what he tried to access. That's just the last page he was on, and pretty useless :(

Is there anyway to see exactly when he typed in the browser before being re-directed to the 404?

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36572876

With regards to the link I posted, you will get a notification that the user was trying to access and not the 404.php url. It will however not be able to tell you that the actual location is as you cannot determine this.

So in short:
1. You will receive an email showing you the page that the user was trying to load for example:
2. You cannot determine what it should have been using code: The only way to do this would be to Analyse the result that the script sends you and then create an additional directory called img and add a page with the same name that directs the user to the correct location.
3. Same as point 1
4. This example that I posted will not send you the as it captures the url that the user was trying to access from the start.

Hope this helps!!!

Author Comment

ID: 36573299
First of all, I definitely don't expect this to redirect the user to the appropriate page, or anything like that. I just want to get an email with the incorrectly typed address.

I wish I could get this software to work like this. I've set it up and it really does simply send me the 404.php url. There are several similar comments on the site. I imagine it's a simple matter of overlooking something obvious, because the author has set it up so you only have to plug in about three variables.

Have you got a working sample of the code I could look at? Or could you forward one of the emails so I could see it in action?

Thanks for your help!
LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36573644
I have tested it on my domain and the output was the following:

There was a 404 Not Found error on the domain

When: Mon Sep 19 2011 12:13:36 pm SAST
(Who) IP Address:
(What) Tried to Access:
(From where) HTTP Referer:

User Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +

Author Comment

ID: 36573674
For me it looks like this:

 404 email notification

Author Comment

ID: 36577017
do you have any ideas? can I see a copy of your code and .htaccess?

I can't figure out what the problem could be ><

LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36578947
My .htaccess has got the following 2 entries in as suggested by the site:

ErrorDocument 404 /error/404.php  
ErrorDocument 403 /error/403.php



header("HTTP/1.0 404 Not Found");	// Send correct HTTP Header
$error_code = '404 Not Found';		// Specify the error code
require_once('');	// Include the error mailer script


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">

<title>404 Not Found - The page or file you requested does not exist.</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<link href="" rel="stylesheet" type="text/css" />

	<div id="wrapper">
		<img src="" alt="404 Error Oops!" title="404 Error Oops!" />
		<h1 class="loud">Sorry! We couldn't find it.</h1>
		<p class="loud">You have requested a page or file which does not exist so we 
		notified the web administrator to check it out.</p>
		<p class="small">Here are a few options to find what you are looking for.</p>
			<li><span>Double check the web address for typos</span></li>
			<li><span>Head back to our home page via the navigation below</span></li>
			<li><span>Contact us by <a href="">clicking here</a></span></li>
			<li><a href="">Home</a></li>
			<li><a href="">Blog</a></li>
			<li><a href="">Free Fax to Email</a></li>
			<li class="last"><a href="">Contact</a></li>
	</div><!-- end div #wrapper -->

Open in new window


Author Comment

ID: 36582546
Can you attach your directory?

i'm confused about this folder 'error'. it is not in the downloadable files on the site, but he references them (as do you) in your .htaccess and in the 404.php file.


Author Closing Comment

ID: 36894024

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question