无法检索完整的SMTP错误日志PHP邮件程序

无法检索完整的SMTP错误日志PHP邮件程序,php,mysql,email,phpmailer,Php,Mysql,Email,Phpmailer,我创建了一个简单的表log,如果邮件无法发送,我会在其中插入记录 mysql> describe log; +--------+-----------+------+-----+---------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +--------+-------

我创建了一个简单的表
log
,如果邮件无法发送,我会在其中插入记录

mysql> describe log;
+--------+-----------+------+-----+---------------------+-----------------------------+
| Field  | Type      | Null | Key | Default             | Extra                       |
+--------+-----------+------+-----+---------------------+-----------------------------+
| id_log | int(11)   | NO   | PRI | NULL                | auto_increment              |
| error  | text      | YES  |     | NULL                |                             |
| time   | timestamp | NO   |     | 0000-00-00 00:00:00 | on update CURRENT_TIMESTAMP |
+--------+-----------+------+-----+---------------------+-----------------------------+
在我的PHP方面,错误日志记录如下:

  foreach ($arrayWithMails as $key => $value) {
        $mail->addAddress($value);
        if (!$mail->send())
        {
            put('message', $mail->ErrorInfo); //store in session
//            echo $mail->ErrorInfo;

        }
        else {
            /* Add email from array in session to be displayed at main page */
            put('emailAddresses', $arrayWithMails); //Store in session

        }
        $mail->ClearAllRecipients();
    }
$log->logError($_SESSION['message']);
mysql> select * from  log;
+--------+------------------------------------------------------------------------------------+---------------------+
| id_log | error                                                                              | time                |
+--------+------------------------------------------------------------------------------------+---------------------+
|      1 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:08:30 |
|      2 | 1                                                                                  | 2016-10-21 15:12:04 |
|      3 | 1                                                                                  | 2016-10-21 15:13:42 |
|      4 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:14:14 |
|      5 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:17:02 |
|      6 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:18:22 |
|      7 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:28:02 |
|      8 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:28:53 |
+--------+------------------------------------------------------------------------------------+---------------------+
它在我的类中调用一个方法,该方法将字符串作为参数传递,并插入到DB中

但是,我所有的日志都是这样的:

  foreach ($arrayWithMails as $key => $value) {
        $mail->addAddress($value);
        if (!$mail->send())
        {
            put('message', $mail->ErrorInfo); //store in session
//            echo $mail->ErrorInfo;

        }
        else {
            /* Add email from array in session to be displayed at main page */
            put('emailAddresses', $arrayWithMails); //Store in session

        }
        $mail->ClearAllRecipients();
    }
$log->logError($_SESSION['message']);
mysql> select * from  log;
+--------+------------------------------------------------------------------------------------+---------------------+
| id_log | error                                                                              | time                |
+--------+------------------------------------------------------------------------------------+---------------------+
|      1 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:08:30 |
|      2 | 1                                                                                  | 2016-10-21 15:12:04 |
|      3 | 1                                                                                  | 2016-10-21 15:13:42 |
|      4 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:14:14 |
|      5 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:17:02 |
|      6 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:18:22 |
|      7 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:28:02 |
|      8 | SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | 2016-10-21 15:28:53 |
+--------+------------------------------------------------------------------------------------+---------------------+
我的SMTP调试设置为
4
。同样使用
2
尝试-结果相同

如果f.e.我执行了
$mail->ErrorInfo
的基本回显,我会得到完整的日志,但当我想在DB中存储完整的日志信息时,我只会得到:
SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
如果我尝试将该错误存储在$\u会话变量中,也会发生同样的情况

知道如何存储完整日志吗?
谢谢

ErrorInfo
仅包含错误消息,而不包含完整的调试日志。调试输出就是这样——默认情况下,它转储到标准输出,而不是保留

要捕获它,您需要查看
Debugoutput
属性-在PHPMailer的最新版本中,您可以将其设置为可调用的,可用于收集调试输出并将其插入数据库中

例如:

//Before sending
$debuglog = '';
$mail->Debugoutput = function($str, $level) use ($debuglog) {
    $debuglog .= $str;
};

//... after calling send()
$log->logError($mail->Errorinfo . ' ' . $debuglog);

这就是我的答案。我正在扩展PHPMailer,我已经包括它将抛出异常,所以这样我就可以正确地获得异常消息

foreach ($array as $key => $value) {
    $mail->addAddress($value);
    try
    {
        if (!$mail->send()) {
            put('message', $mail->ErrorInfo); // Storing for frontend, that error exist, for detailed info - log is in DB

        }
        else {
            /* Add email from array in session to be displayed at main page */
            put('emailAddresses', $array);
        }
    } catch (phpmailerException $exc)
    {
        $debugError = $exc->errorMessage();
    }

    $mail->ClearAllRecipients();
}
$log->logError($debugError);

你好,谢谢你的帮助。实际上,我不确定如何在我的代码中实现您的解决方案。我已经编辑了我的问题。这种方法不会让您有任何进一步的了解,因为异常中的消息将与ErrorInfo中的消息相同。@Synchro nop mate,我得到这个输出,例如:
select*from log;+----------+-------------------------+-------------++\124;id|U log | error | time |+--------------------------------------+----------------------------+| 77 | SMTP错误:无法进行身份验证。|2016-10-21 18:51:42 |+---------------------------------------------++
但这不是你要的成绩单,这是你要的吗?就目前而言,这已经足够了信息:))谢谢!