Get email not send errors

How can I get the error message for the mail() function?

You can use error_get_last()when mail() returns false.

$success = mail(‘’, ‘My Subject’, $message);
if (!$success) {
$errorMessage = error_get_last()[‘message’];
With print_r(error_get_last()), you get something like this:

[type] => 2
[message] => mail(): Failed to connect to mailserver at “x.x.x.x” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()
[file] => C:\www\X\X.php
[line] => 2

Please follow and like us: