PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 7, 2022

[FIXED] How to hide the logs of PHPMailer?

 July 07, 2022     gmail, php, phpmailer, server, smtp     No comments   

Issue

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

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


Answered By - Syscall
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing