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 include_once 'header.php';?>
With:
<?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". "\n\nDetails\n----------------------------------------------------------------------". "\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. "\n\nUser Agent: ".$http_agent; mail("you@yourdomain.com", "maxbeatty.com 404 report", $msgbody, "From: 404@yourdomain.com\n"); include_once 'header.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!



July 22nd, 2009 at 8:26 am
Thank you. Read with interest. Blog is brought to favorites =).
July 29th, 2009 at 7:43 am
Interested in earnings for the Webmaster?.
July 30th, 2009 at 1:26 pm
The author, and you do not accidentally from Moscow?.
July 31st, 2009 at 7:36 pm
Thanks for all the answers:) In fact, learned a lot. This is only until the end and not разобрался that and from where..
August 2nd, 2009 at 1:34 am
Exciting.
August 3rd, 2009 at 8:05 am
Post a good, zakinu site to your bookmarks..
August 3rd, 2009 at 1:04 pm
Elki-sticks, unique tip.
August 3rd, 2009 at 4:02 pm
Collection of material was surprised! It leaves the feeling that all this must be read and have enough for a long evening. Bookmark.
August 4th, 2009 at 2:54 pm
Useful инфа, put in your bookmarks, and added in the news, let others read the same.
August 5th, 2009 at 3:00 pm
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..
August 5th, 2009 at 8:49 pm
The author perfectly. Just do not poke where you can only advertising.
August 6th, 2009 at 6:32 am
Posted on his website narodovskom link to this post. I think many will be interested!.
August 7th, 2009 at 2:26 am
Yeah, now it is understandable … And then I just not even know where it is not us with the title ….
August 7th, 2009 at 1:10 pm
What is to be expected, wrote atypical otzheg!.
August 8th, 2009 at 11:51 am
Nice post, but a lot of excess..
August 8th, 2009 at 11:02 pm
I subscribed to the RSS feed, but the message for some reason in the form of some characters: (How do I fix this?.
August 9th, 2009 at 11:41 am
The theme of your pretty complicated for a beginner..
August 9th, 2009 at 8:55 pm
Read with great interest, very interesting story. Begin to remember, I still started.
August 11th, 2009 at 5:45 am
Collection of material was surprised! It leaves the feeling that all this must be read and have enough for a long evening. Bookmark.
August 11th, 2009 at 9:44 am
Make your first post, but it is not published. I am writing the second. It’s me, the African tourist.
August 11th, 2009 at 3:18 pm
The author continued with the same spirit.
August 11th, 2009 at 5:42 pm
As a Newbie, I am always searching online for articles that can help me. Thank you
August 12th, 2009 at 3:35 pm
success in business with this blog.
August 13th, 2009 at 8:12 am
Also quote your article in your blog.
August 14th, 2009 at 12:36 am
Something I do not see the feedback form, or other co-ordinates the administration of your blog..
August 14th, 2009 at 7:54 am
And now I wonder as the author reads the comments on this post. Or are we here for themselves write?.
August 15th, 2009 at 6:24 am
Yeah … Here people used to say: ABC teach – in all hut shout:).
August 17th, 2009 at 12:12 am
I must admit, webmaster nakropal test..
August 22nd, 2009 at 8:45 am
Gratifying that your blog is constantly evolving. Such positions only adds popularity..
August 23rd, 2009 at 5:40 am
If you really wrote it for beginners, the cost to sign in more detail ….
August 24th, 2009 at 4:04 pm
Thank you for your article! I hope the author do not mind, if I use it for their course..
August 25th, 2009 at 10:16 pm
I have carefully read the second paragraph and not the substance contained vkuril.
August 26th, 2009 at 2:36 pm
A case of you do not manage blogs on related topics? Do you have excellent and a lot of hits, I’m Watching.
September 10th, 2009 at 5:47 am
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
October 28th, 2009 at 1:19 pm
Thanks !! very helpful post!
October 29th, 2009 at 3:29 pm
I found this information very interesting and I am looking forward to more posts!
October 31st, 2009 at 2:46 am
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?
November 2nd, 2009 at 4:10 pm
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.
November 3rd, 2009 at 6:41 pm
@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.
February 3rd, 2010 at 6:18 pm
Useful post and great read. Thanks.
February 9th, 2010 at 11:51 pm
Wow
April 7th, 2010 at 12:26 am
This an Great post, I will save this post in my Mixx account. Have a great day.
June 13th, 2010 at 10:08 pm
This an Fantastic post, I will bookmark this in my StumbleUpon account. Have a great day.