Search code examples
phpserversmtpgmailphpmailer

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   = "myemail@gmail.com";
  $mail->Password   = "mypass";
  $mail->IsHTML(true);
  $mail->setFrom('bibibibi@gmail.com');
  $mail->addAddress('lalala@gmail.com');
  $mail->msgHtml($messaggio_email);
  $mail->Subject = $object;
if(!$mail->Send()) {
  echo "something went wrong";
  var_dump($mail);
} else {
  echo 'Email sent';
}


Solution

  • 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;