PHPMailer sent message, but returned CLIENT/SERVER dialog to browser

khrfx4 picture khrfx4 · Feb 4, 2014 · Viewed 7.9k times · Source

So I've searched Google and Stackoverflow and I'm a bit surprised I could not find this problem.

I'm using XAMPP/localhost and PHPmailer sending an email to my yahoo account using my gmail email account. Everything worked perfectly with the email being send and received, including a sample attachment.

The problem is my browser is displaying what appears to be a dialog of the SERVER/CLIENT for each step of the behind the scene processing just before the "Sent successful" message.

Sample output here:

2014-02-04 05:44:36 SERVER -> CLIENT: 220 mx.google.com
ESMTP xv2sm62192389pbb.39 - gsmtp
2014-02-04 05:44:36 CLIENT -> SERVER: EHLO localhost
2014-02-04 05:44:36 SERVER -> CLIENT: 250-mx.google.com at your service, [171.6.91.113] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250 CHUNKING
2014-02-04 05:44:36 CLIENT -> SERVER: AUTH LOGIN
2014-02-04 05:44:36 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2014-02-04 05:44:36 CLIENT -> SERVER: a2hyZng0NDRAZ21haWwuY29t
2014-02-04 05:44:37 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2014-02-04 05:44:37 CLIENT -> SERVER: RnV0dXJlMTA= 
2014-02-04 05:44:38 SERVER -> CLIENT: 235 2.7.0 Accepted 
.
.  25 more lines of this stuff
.
2014-02-04 05:44:40 CLIENT -> SERVER: QUIT 
2014-02-04 05:44:40 SERVER -> CLIENT: 221 2.0.0 closing connection xv2sm62192389pbb.39 - gsmtp 
Message has been sent

I put line breaks in to make it more readable, but it comes out as one long string on the screen.

Here is the code. How do I suppress this output?

require_once "../phpmailer/class.phpmailer.php";

$mail = new \PHPMailer(true); 

$mail->IsSMTP();
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;
$mail->SMTPDebug  = 2;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = 'ssl';
$mail->Username   = "[email protected]";
$mail->Password   = "xxx";
$mail->SetFrom('[email protected]', 'Randy S');
$mail->WordWrap = 50;

$mail->AddAddress('[email protected]', 'Randy');
$mail->Subject = 'PHPMailer Test Subject';
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer."; 
$mail->AddAttachment('upload/names.txt');      // attachment

if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo; 
} else {
echo "Message has been sent";
} 

Answer

AyB picture AyB · Feb 4, 2014

Comment or remove this line or set it to 0:

$mail->SMTPDebug  = 2; 

It's used to display errors and messages.

From the PHPMailer site:

$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only