【问题标题】:PHPMailer sent message, but returned CLIENT/SERVER dialog to browserPHPMailer 发送消息,但返回 CLIENT/SERVER 对话框到浏览器
【发布时间】:2014-02-28 00:09:53
【问题描述】:

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

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

问题是我的浏览器在“发送成功”消息之前显示似乎是服务器/客户端的对话框,用于幕后处理的每个步骤。

此处的示例输出:

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";
} 

【问题讨论】:

  • 对不起,这是重复的。我用不同的词搜索,最后在这里找到了答案:stackoverflow.com/questions/19117816/… 零“0”或“假”将适用于 SMTPDebug 参数。
  • 当您下载类库时,请阅读自述文件...该信息非常基本,并且在其中。

标签: php email localhost phpmailer


【解决方案1】:

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

$mail->SMTPDebug = false;

在邮件发送脚本中

$mail->WordWrap = 50;

会有用的

【讨论】:

    【解决方案2】:

    SMTPDebugclass.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;
    

    【讨论】:

      【解决方案3】:

      注释或删除此行或将其设置为0

      $mail->SMTPDebug  = 2; 
      

      用于显示错误和消息。

      来自 PHPMailer 网站:

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

      【讨论】:

      • 谢谢你,先生.. 你的回答让我很开心.. Thax
      猜你喜欢
      • 2021-09-12
      • 2019-10-25
      • 2019-01-02
      • 2021-07-11
      • 2015-04-07
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 2011-11-09
      相关资源
      最近更新 更多