PHPMailer发送消息,但返回CLIENT / SERVER对话框到浏览器

时间:2014-02-04 06:28:56

标签: php email localhost phpmailer

所以我搜索了谷歌和Stackoverflow,我有点惊讶我找不到这个问题。

我正在使用XAMPP / localhost和PHPmailer使用我的Gmail电子邮件帐户向我的yahoo帐户发送电子邮件。一切都与发送和接收的电子邮件完美配合,包括样本附件。

问题是我的浏览器正在显示“发送成功”消息之前的场景处理后面每一步的SERVER / CLIENT对话框。

此处的示例输出:

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

我设置换行符以使其更具可读性,但它在屏幕上显示为一个长字符串。

这是代码。如何抑制此输出?

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   = "xxx@gmail.com";
$mail->Password   = "xxx";
$mail->SetFrom('xxx@gmail.com', 'Randy S');
$mail->WordWrap = 50;

$mail->AddAddress('xxx@yahoo.com', '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";
} 

3 个答案:

答案 0 :(得分:21)

评论或删除此行或将其设置为0

$mail->SMTPDebug  = 2; 

它用于显示错误和消息。

来自PHPMailer网站:

  

$ mail-> SMTPDebug = 2; //启用SMTP调试信息(for   测试)
                          // 1 =错误和消息
                          // 2 =仅消息

答案 1 :(得分:1)

SMTPDebug定义的

class.phpmailer.php如下。根据这一点,您应该将SMTPDebug初始化为0.因此,不会显示任何命令或数据消息。此外,通过使用PHPMailer类的ErrorInfo字段,可以在发生错误时查看错误消息。

/**
 * 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;

答案 2 :(得分:0)

我遇到了同样的问题, 添加

$mail->SMTPDebug = false;

之后的邮件发送脚本中

$mail->WordWrap = 50;

它会起作用