Testing mail() On Apache

Here is a simple way of testing if your mail() function is working. I’ve used this script to test if the mail servers are properly working. From time to time I’m asked to migrate websites to new DNS’s. When I’m setting up the MX Records, I need to test to make sure the server sends / receives e-mails.

To test outgoing mail using PHP’s mail() function, simply create testmail.php and use this:

[code lang=”php”]
Message successfully sent!

“);
} else {
echo(“

Message delivery failed…

“);
}

?>
[/code]

Very straight forward, set $to variable to your own e-mail. Edit the $subject and $body if needed. The if conditional will e-mail you if the mail() function exists! Otherwise, you get fail. 🙁

Published by

CodeSleepShred

Born and raised in the Pacific Northwest, there are only a few things to do during the rainy season: code, sleep, shred.