Maria Scetta
Maria Scetta

Reputation: 71

How to hide the logs of PHPMailer?

My code works but when I send an Email I see this long block on informations that starts like this:

2021-03-06 13:42:26 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:26 CLIENT -> SERVER: STARTTLS
2021-03-06 13:42:27 CLIENT -> SERVER: EHLO localhost
2021-03-06 13:42:27 CLIENT -> SERVER: AUTH LOGIN
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]
2021-03-06 13:42:27 CLIENT -> SERVER: [credentials hidden]

...and goes on writing al the informations about PHPMailer.

I don't want everyone to see it after they send an Email, how can I hide it?

that's my code:

if($errore == 0){
  $message_email = 'Messaggio inviato da: '.$name.' '.$surname.'<br>';
  $message_email .= 'Email: '.$email.'<br>';
  $message_email .= 'Telefono: '.$number.'<br>';
  $message_email .= 'Oggetto: '.$object.'<br>';
  $message_email .= 'Corpo: '.$message.'<br>';
  require 'PHPMailer.php';
  require 'Exception.php';
  require 'SMTP.php';
  

  $mail = new \PHPMailer\PHPMailer\PHPMailer();
  $mail->IsSMTP();
  $mail->Mailer = "smtp";
  $mail->SMTPDebug  = 1;  
  $mail->SMTPAuth   = TRUE;
  $mail->SMTPSecure = "tls";
  $mail->Port       = 587;
  $mail->Host       = "smtp.gmail.com";
  $mail->Username   = "[email protected]";
  $mail->Password   = "mypass";
  $mail->IsHTML(true);
  $mail->setFrom('[email protected]');
  $mail->addAddress('[email protected]');
  $mail->msgHtml($messaggio_email);
  $mail->Subject = $object;
if(!$mail->Send()) {
  echo "something went wrong";
  var_dump($mail);
} else {
  echo 'Email sent';
}

Upvotes: 2

Views: 3325

Answers (2)

Abrar Hussain
Abrar Hussain

Reputation: 1

Make sure to put any of following codes in the try { } block to make it work.

$mail->SMTPDebug  = SMTP::DEBUG_OFF; 

OR

 $mail->SMTPDebug  = 0; 

Upvotes: 0

Syscall
Syscall

Reputation: 19779

You need to change the "SMTP class debug output mode." using the SMTPDebug property.

$mail->SMTPDebug  = SMTP::DEBUG_OFF;

Your actual value (1) corresponding to DEBUG_CLIENT.

But you should use one of the following allowed values :

  • SMTP::DEBUG_OFF: No output
  • SMTP::DEBUG_CLIENT: Client messages
  • SMTP::DEBUG_SERVER: Client and server messages
  • SMTP::DEBUG_CONNECTION: As SERVER plus connection status
  • SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed

Upvotes: 4

Related Questions