I'm in the process of customizing dp-error.php. I'm using the mail() function to alert me when there's a database connection problem on my website. The trouble is, what if 1000 people visit my website when it's down? Wouldn't I get 1000 emails? Here's the code I'm using to send email:

mail("[email protected]", "Database Error", "There is a problem with teh database!", "From: Your WP Installation"); ?> 

My other question is then how would mail() know it's okay to send me a notification email in a future db error? After a certain period of time send again, if there's (still) an error?


  • Close-voted as off-topic. This is a question about a PHO function, that is not WordPress-specific. Mar 5, 2013 at 23:25

1 Answer 1


I'm not sure that this is a good idea, email is just not a good medium for emergency messages (who will see the email when you are a sleep or at the beach?), and if you want to monitor the site it is better done by external service which will probably be able to send you an SMS or make a phone call.

That being said, if you want to still send emails, you need to store the last error time in a separate file, and before sending a mail read the file and check when was the last time a mail was sent. The important detail here is that the file need to be writable by the web server. It is probably a good idea to locate it outside of the web root on your server.

  • Thanks.. I didn't consider an external monitoring service. I'll look in to that. But, thanks for the response.
    – Mark Bubel
    Mar 7, 2013 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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