【问题标题】:phpmailer debug output to html variablephpmailer 调试输出到 html 变量
【发布时间】:2014-11-25 09:17:20
【问题描述】:

我希望使用 php 邮件调试信息在网页中显示。当我启用调试时,它只是回显字符串。这意味着我的 html 出现故障,因此我希望将其作为变量输出,以便将输出 html 放置在我想要的位置。

$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';

【问题讨论】:

    标签: php html phpmailer


    【解决方案1】:

    PHPMailer allows Debugoutput to be a closure 的最新更改,因此您可以让它做任何您喜欢的事情,例如收集所有调试输出并稍后发出:

    $debug = '';
    $mail->Debugoutput = function($str, $level) {
        $GLOBALS['debug'] .= "$level: $str\n";
    };
    //...later
    echo $debug;
    

    【讨论】:

    • 这不是在}后面少了一个;吗?
    • 除非我遗漏了什么,目前 PHPMailer 中似乎存在一个错误,其中 $str 在上面的函数中不包含调试输出,而是只包含简短的错误(与存储在 $mail->ErrorInfo 中)。即使设置为 $mail->SMTPDebug = 4; 也会发生这种情况
    • 我想通了。当出现错误时,不会调用回调函数一次,而是多次调用回调 - 每行调试信息一次。因此,您必须确保如上所述将 $str 变量连接到您的 $GLOBALS['debug'] 变量(而不是像我一样分配变量),否则您只会得到调试信息的最后一行...通常与 $mail->ErrorInfo. 相同
    猜你喜欢
    • 2020-09-24
    • 2017-10-29
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多