Email me my site errors

31 March, 2007

Show comments

Have you ever wondered what the reason for that 404 error is when you set debug to 0, or when you move your site onto your live server? How many visitors/clients are confronted by a 404 when they should be looking at the fruits of your work? Cake allows you to modify what happens in the case of an error, and the purpose of this post is to show how to make your site mail you (or the website admin if it's not you) or take whatever other action you might want whenever a 404 is generated.

I'll keep it short and sweet today :). Create the file app/app_error.php app/error.php with the contents below:

Include this file anywhere in your code, bootstrap is as good a place as any, with include(APP.'app_error.php');. and that's it. Whenever your site generates an error you get an email with the basics, and more details in the log file. A related bit of info is available over on Cakebaker's blog, which is where I realized that if you name the file 'error.php' it gets included automatically.

Bake on!