-2

Currently this just displays 'Error':

    if(@mail($email,$email_subject,$email_content)) {
    echo 'Message sent!'; 
} else {
    echo 'ERROR!';
}

How can I display the actual error?

Thanks

zigg76
  • 55
  • 1
  • 7

1 Answers1

0

Average Level Code

ob_start();
$result=mail($email,$email_subject,$email_content);
$err=ob_get_clean();
if($result) {
   echo 'Message sent!'; 
} else {
   echo "ERROR: {$err}";
}

Why

  • You not have to throw and catch an real exception
  • You can write the error on the page where you need it
  • simple fix, without need of extra stuff

But you have to set error_reporting() to an proper level, if the errors from mail() will still not show up.

JustOnUnderMillions
  • 3,741
  • 9
  • 12