Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


error 404 - automatic email

Posted on 2003-03-11
Medium Priority
Last Modified: 2010-03-04
I have the:
ErrorDocument 404 /missing.html
working OK, and a pretty message going to the user.

But how do I get this page to automatically email me the URL they were tring to go to, and/or where they were coming from (which page has the bad url on it)

Can this be done?

Question by:arobertson
  • 2
LVL 15

Expert Comment

ID: 8117437

You could redirect the 404 Error to some cgi scripts, which could return the $ENV{REQUEST_URI}, back to user, or as email it to you as you wish.



Author Comment

ID: 8123499
Not up on CGI.
Can you point me to a sample?

LVL 15

Accepted Solution

samri earned 200 total points
ID: 8125699

What is your OS.  If you are running Unix then, it will be much easier, since I would use perl.

-- some rude code that I had.  Mine is running on Win2K with ActivePerl.  You if you are running on Unix, change c:/perl/bin/perl to /bin/perl (or /usr/local/bin/perl) or wherever your perl is)/



use CGI;
use Mail::Sendmail;

my $q=new CGI;

print $q->header;
print $q->start_html;
my $remote_addr=$ENV{'REMOTE_ADDR'};
my $referer=$ENV{'HTTP_REFERER'};
my $url=$ENV{REQUEST_URI};

print "404 Not Found<br>";
print "$url<br>";
print "<hr>";

print $q->end_html;

 %mail = (
   To => 'Your Name <userself@yourdomain.com>',
   From => 'Web server <weberror@webserver>',
   Subject => 'Web Error',
  'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",

 $mail{Smtp} = 'yoursmtp.domain.com';
 $mail{'Message : '} = "FROM IP\t:$remote_addr\nFROM URL\t:$referer\nURL:$url\n";

  sendmail %mail;

# the following will print a debugging on browser.
# if (sendmail %mail) { print "Mail sent OK.\n" }
#   else { print "Error sending mail: $Mail::Sendmail::error \n" }
# print "\n\$Mail::Sendmail::log says:\n", $Mail::Sendmail::log


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

572 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