Hello @kartik,
You can use error_get_last() when mai l()returns false.
$success = mail('example@example.com', '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
Hope it helps!!
Thank you!!