Custom Database Error Page Template with Email Notification For WordPress

Print View Mobile View

Unlike the WordPress maintenance page, database error is usually unexpected. The db-error.php page template will provide a user friendly message to your site visitors in the event of a database error. Furthermore, when the page is displayed, an email notification is sent with the URL of the page where the error occurred to the address of your choice.
wordpress database error template

header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
header( 'Status: 503 Service Temporarily Unavailable' );
header( 'Retry-After: 600' ); // 10 minutes
$mailto 	= "[email protected]";
$mailfrom 	= "From: [email protected]";
$message	= "There was an error while accessing the database. ". 
			  "It broke when someone tried to open this page: 
$subject	= "Database error at ".$_SERVER['SERVER_NAME'];
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
	<title>Database Connection Error | SumTips</title>
	<meta charset="utf-8" />
	<style type='text/css'>
	body {
		background: #fff;
		font: 16px Georgia, serif;
		line-height: 1.3;
		margin: 0;
		padding: 0;
	#content {
		background: #fff url(/wp-content/dberror.png) no-repeat left top;
		height: 225px;
		margin: 80px auto 0;
		padding: 75px 50px 0 300px;
		width: 375px;
	h1 {
		font-size: 34px;
		font-weight: normal;
		margin-top: 0;
	p {
		margin: 0 0 10px 5px;

<div id="content">
	<h1>Database missing!</h1>
	<p>Looks like the database got lost somewhere....</p>
	<p>Don't worry though! We'll recover it!<p>
	<p>In the mean time, you can read the last 10 posts <a href="">here on FeedBurner</a>.<p>
</div><!-- #content -->

<?php die(); ?>

How to Use?

Just create a new file named db-error.php inside wp-content directory and paste in the above code in it. Remember to replace email address with your own.

The db-error.php file is kept as an independent file in the WordPress installation, so it’s not affected by core upgrades. [via Aliso]