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";
}
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"; } ?>
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.
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. * ).
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With