Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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";
} 
like image 974
khrfx4 Avatar asked Feb 04 '14 06:02

khrfx4


People also ask

How do I know if PHPMailer is working?

to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>

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.

How many emails can I send with PHPMailer?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *. secureserver. * ).


1 Answers

SMTPDebug defined at class.phpmailer.php as below. According to this, you should initialize SMTPDebug as 0. Thus, any command or data messages won't be shown. Also, you can view error message when error occurred by using ErrorInfo field of PHPMailer class.

/**
 * SMTP class debug output mode.
 * Debug output level.
 * Options:
 * * `0` No output
 * * `1` Commands
 * * `2` Data and commands
 * * `3` As 2 plus connection status
 * * `4` Low-level data output
 * @type integer
 * @see SMTP::$do_debug
 */
public $SMTPDebug = 0;
like image 92
lonesomecodeboy Avatar answered Oct 13 '22 00:10

lonesomecodeboy