Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Is it possible to send an automatic email that includes details about the requested page to the webmaster when a visitors hits a 500 internal server error page?

That way the web master could act more quickly to solve the problem. This is a general question so which platform is used is irrelevant.

share|improve this question
1  
please add web server software and language you can(want) use. (apache, nginx, iis, php, asp) so people will be able to show you script examples. –  jflaflamme Jan 17 '12 at 10:10

5 Answers 5

up vote 7 down vote accepted

Yes, it's possible. You just need to ascertain whether the web server is IIS or Apache and then you can set it to show a custom page (which will contain the code to capture the details you want from the user and e-mail it to you) whenever a 500 error is encountered.

For Apache, for instance, it's really simple. Simply create (or add if one exists) a .htaccess and use the following rule within it to set up your custom error document:

ErrorDocument 500 /error-docs/500.php
share|improve this answer
    
and now for nginx? :) –  rogerdpack Apr 14 at 14:31

Yes, very possible. Except email, you can also check Web Server log.

I suggest don't send email on every single 500, otherwise if theres a bug, you mailbox will get flooded. Just record the error id, send 1 for the same error on same id.

share|improve this answer
    
My take is that recieving a email when something goes wrong makes the life of the webmaster a little easier instead of going through the web server log regualary. Good point about the 1 email idea. Upvote! –  Tony Bolero Jan 10 '12 at 13:07
    
Thanks. I was use ASP, in old time, the ASP gets an error code, I use it and the url of the page, make a unique key and save to memory, I got 1 email on every error and on every time memory flushed (e.g. app reboot). Not so many email, but enough to track errors. (btw, this way also can track 404, but be careful, these days too much 404 error from bots) –  Eric Yin Jan 10 '12 at 13:11

Sending a mail with every error, via a custom error page, may not work if the problem is with PHP related: your custom page may not run either so the mail doesn't go out. Also you'll get one email per error which could be a flood.

I'd suggest instead implementing some form of log scanning: have a cron job (or scheduled task under Windows) scan the log files for errors every day or every few hours and send a summary of anything found since the last check to the relevant admin(s). You could also make your log checking script do a few other things like make sure the web server service (and any database services and so forth) is running, if only for paranoia's sake. If nothing else, one email per reporting period can cover other HTTP error codes (401, 404, ...) and other things found in the logs. If you do this, always send the email message even if nothing is wrong: that way you know if your scanning script has failed to run because you stop getting messages (otherwise no message could either mean all is well or the damage report machine is damaged).

share|improve this answer
    
Alternatively, you can hook into the logging process directly on Apache by having it write (or pipe) log entries to a perl script or a database which supports hooks and user-defined functions (or is capable of sending email other ways). You can also intercept Apache log events using a custom module. –  Lèse majesté Jan 14 '12 at 0:42
    
Upvoted, I think your answer really deserve to be upvoted. that's practical solution. –  web designer Jan 14 '12 at 7:32

Yes, send an email for every error. It's also a good idea to send as much info as you can get as part of the email. Think about grabbing:

  • the contents of the form collection,
  • all session variables,
  • the browser user-agent string,
  • cookie values,
  • the page URL, including any querystring parameters.

This helps greatly for debugging purposes. It's trivial to get this info in classic ASP and ASP.NET via the Request and Session objects.

Just don't have an error on your custom error page, or you'll freak out the web server.

share|improve this answer

You can add an iframe that loads a php from other server, then your error page will always send mails.

share|improve this answer
1  
Why an iframe? Not sure I understand the reason. –  Andrew Sep 17 '12 at 8:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.