php - How to prevent an error to display to user -
i have simple code sending mails. sometime $host
might not available or smtp
server might down happens in these cases swiftmailer
throws lot of exceptions , $result
despite of returning true
or false
give me complete mess of errors.
so how can turn off errors page of code but not whole library?
$transport = swift_smtptransport::newinstance(self::$host, 25) ->setusername(self::$username) ->setpassword(self::$password); //create mailer using created transport $mailer = swift_mailer::newinstance($transport); $message = swift_message::newinstance("custom sheets"); $message->setfrom(array('edb@abc.com.pk' => 'approval of custom duty sheet')); $message->setto($to); $message->setbody($html,'text/html'); //send message $result = $mailer->send($message);
you can catch exception , handle it:
try { $transport = swift_smtptransport::newinstance(self::$host, 25) ->setusername(self::$username) ->setpassword(self::$password); //create mailer using created transport $mailer = swift_mailer::newinstance($transport); $message = swift_message::newinstance("custom sheets"); $message->setfrom(array('edb@abc.com.pk' => 'approval of custom duty sheet')); $message->setto($to); $message->setbody($html,'text/html'); //send message $result = $mailer->send($message); } catch(exception $e) { // handle error here }
turning off errors / warnings / notices in general:
error_reporting(-1);
Comments
Post a Comment