Email Yourself Detailed 404 Errors from WordPress and Filter with Gmail
One of the first things you learn to do in web development is make sure everything works. Do all of your links work correctly? Do all of your images show up? And as your website progresses and grows, is someone linking to one of my pages that doesn’t exist anymore? Or are people looking for a page they think should exist but doesn’t? You can check on all of that with some basic testing and looking through boring server logs, or you could make your website work for you and tell you when someone couldn’t find something.
In WordPress, when a page or file can’t be found a user is redirected to the 404.php page. Mine looks like this:
I came across a great tutorial from Nettuts+ for creating a PHP auto-mailer for 404 and 403 errors, but since WordPress already had it’s own 404.php page, I decided to simplify their method a bit.
At the top of my WordPress theme’s 404.php page, I added some simple PHP to get environmental variables, construct an email, then mail it to myself before loading the rest of the page.
Replace:[php]<?php include_once ‘header.php’;?>[/php]
With:[php]<?php
# Gather visitor information
$ip = getenv("REMOTE_ADDR"); // IP Address
$server_name = getenv("SERVER_NAME"); // Server Name
$request_uri = getenv("REQUEST_URI"); // Requested URI
$http_ref = getenv("HTTP_REFERER"); // HTTP Referer
$http_agent = getenv("HTTP_USER_AGENT"); // User Agent
$error_date = date("D M j Y g:i:s a T"); // Error Date
$msgbody =
"There was a 404 error on the ".$server_name." domain".
"nnDetailsn———————————————————————-".
"nWhen: ".$error_date.
"n(Who) IP Address: ".$ip.
"n(What) Tried to Access: http://".$server_name.$request_uri.
"n(From where) HTTP Referer: ".$http_ref.
"nnUser Agent: ".$http_agent;
mail("you@yourdomain.com", "maxbeatty.com 404 report", $msgbody, "From: 404@yourdomain.comn");
include_once ‘header.php’;
?>[/php]
Now every time there is a 404 error in WordPress, you’ll get an email about it. But wait, do you really want your inbox cluttered with error emails you may not be able to address until the weekend? No– enter Gmail filters.
In Gmail, go to Settings then click on Filters. You want to label any emails from ‘404@yourdomain.com’ as ‘404 Errors’, tell them to skip the inbox, and never be marked spam because odds are the URLs and technical details will look spammy.
Then when you have time to look over errors that your site has produced for the day/week/month, they’ll all be waiting for your review under the ‘404 Errors’ label in Gmail. From there you can try to recreate and diagnose the problems.
If you’re lazy or scared of editing code, there are WordPress plugins our there to do all of this for you and even enhance your boring 404 landing page.
- 404 Notifier is a plugin that will send you emails anytime a 404 error is produced. You might still want to set up a Gmail filter for their emails.
- 404 SEO Plugin will “automatically display links to relevant pages on your site, based on the words in the URL that was not found.”
- Smart 404 will “perform a search of your posts, pages, tags and categories, using keywords from the requested URL. If there’s a match, redirect to that content instead of showing the error. If there’s more than one match, the 404 template can use some template tags to provide a list of suggestions to the visitor.” I think this could be annoying if a user KNOWS what they are looking for, but could be helpful if a user has a typo in the URL.
Hope this quick copy/paste will improve your site and help your users find what they’re looking for!



Thank you. Read with interest. Blog is brought to favorites =).
Interested in earnings for the Webmaster?.
The author, and you do not accidentally from Moscow?.
Thanks for all the answers:) In fact, learned a lot. This is only until the end and not разобрался that and from where..
Exciting.
Post a good, zakinu site to your bookmarks..
Elki-sticks, unique tip.
Collection of material was surprised! It leaves the feeling that all this must be read and have enough for a long evening. Bookmark.
Useful инфа, put in your bookmarks, and added in the news, let others read the same.
I almost accidentally went to this site, but stay here for long. Delayed, because everything is very interesting. Be sure to tell you about all your friends..
The author perfectly. Just do not poke where you can only advertising.
Posted on his website narodovskom link to this post. I think many will be interested!.
Yeah, now it is understandable … And then I just not even know where it is not us with the title .…
What is to be expected, wrote atypical otzheg!.
Nice post, but a lot of excess..
I subscribed to the RSS feed, but the message for some reason in the form of some characters: (How do I fix this?.
The theme of your pretty complicated for a beginner..
Read with great interest, very interesting story. Begin to remember, I still started.
Collection of material was surprised! It leaves the feeling that all this must be read and have enough for a long evening. Bookmark.
Make your first post, but it is not published. I am writing the second. It’s me, the African tourist.
The author continued with the same spirit.
As a Newbie, I am always searching online for articles that can help me. Thank you
success in business with this blog.
Also quote your article in your blog.
Something I do not see the feedback form, or other co-ordinates the administration of your blog..
And now I wonder as the author reads the comments on this post. Or are we here for themselves write?.
Yeah … Here people used to say: ABC teach — in all hut shout:).
I must admit, webmaster nakropal test..
Gratifying that your blog is constantly evolving. Such positions only adds popularity..
If you really wrote it for beginners, the cost to sign in more detail .…
Thank you for your article! I hope the author do not mind, if I use it for their course..
I have carefully read the second paragraph and not the substance contained vkuril.
A case of you do not manage blogs on related topics? Do you have excellent and a lot of hits, I’m Watching.
This is one of the best 404 report scripts I’ve found…
Thanks for your quality work.
BTW if your new this will work on websites, tested
on Linux Apache/1.3.14 and FreeBSD UNIX Apace/2.2.13.
Will need to change .htaccess or conf to
# Error Pages
ErrorDocument 404 /404.php
Whatever you host requires.
Again thanks Max Beatty
Thanks !! very helpful post!
I found this information very interesting and I am looking forward to more posts!
Random question: I was told to start a blog so that my clients or potential clients could connect with me, I am a photographer. Do you find that happening with your readers?
The capability to manage your emotions and take full responsibility for your life is one of the necessary skills that will enable you to achieve victory, stability, and bliss.
@Hank: Yes, I’ve had old clients benefit from my blog and found new ones because of it. I highly recommend a blog and if you need help setting one up shoot me an email.
Useful post and great read. Thanks.
Wow
This an Great post, I will save this post in my Mixx account. Have a great day.
This an Fantastic post, I will bookmark this in my StumbleUpon account. Have a great day.
This was a informative great writeup by you hope to visit more very soon.