Often it's helpful to find the exact error message that is triggered by the mail() function. While the function doesn't provide an error directly, you can use error_get_last() when mail() returns false.
<?php
$success = mail('[email protected]', 'My Subject', $message);
if (!$success) {
$errorMessage = error_get_last()['message'];
}
?>
(Tested successfully on Windows which uses SMTP by default, but sendmail on Linux/OSX may not provide the same level of detail.)
Thanks to https://stackoverflow.com/a/20203870/195835