Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable error messages in PHPMailer?

How do I disable the error messages from the PHPMailer class? I'm displaying my own error messages and I don't want users to see errors such as "SMTP Error: Could not connect to SMTP host."

Thanks

like image 942
Richard Avatar asked Jan 25 '11 20:01

Richard


People also ask

Does PHPMailer use SMTP?

Local Mail Server Limitation Mail() function usually needs local mail server for sending out emails whereas PHPMailer uses SMTP. Also, you should have authentication credentials.

What is PHPMailer SMTP?

The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP client allows email sending on all platforms without needing a local mail server.

How to send emails with PHP mail() function and PHPMailer?

To send an email using the PHP mail feature, create a new PHP file in the public_html directory and input the mail() function. Then, execute the script using your web browser.


2 Answers

I know this thread is old and already answered but I stumbled here because I had the same problem but ending up solving it differently so I thought I'd share. NOTE: I'm using PHPMailer v5.1.

When you instantiate the PHPMailer class, it takes one optional argument, $exceptions. That tells PHPMailer if it should throw exceptions if it encounters any. It defaults to false which means it does not throw any exceptions, just echoes its messages out. However, if you call it like

  $mail = new PHPMailer(true);

you will tell it to throw exceptions. You can then catch those exceptions and deal with them however you choose. To me, that is much cleaner and more elegant than messing with the source code or disabling the error reporting.

like image 107
heath Avatar answered Nov 12 '22 13:11

heath


This is the way PHPMailer wants you to do it; does not involve editing the original class file.

$mail->SMTPDebug = false;
$mail->do_debug = 0;
like image 31
sbuck Avatar answered Nov 12 '22 14:11

sbuck