douyun3887 2019-07-28 13:42
浏览 158

如何使用FILE_OVERWRITE代替FILE APPEND,以便我可以根据smtp.log中的一行启动操作

I have been playing around with PHPMAILER debug output to file so i can use the log to know what error is being thrown and then do a function based on the error, I have achieved that with the code below to write the log into smtp.log

$mail->SMTPDebug = 2; 
$mail->Debugoutput = function($str, $level) { 
file_put_contents('smtp.log', gmdate('Y-m-d H:i:s'). "\t$level\t$str
", FILE_APPEND | LOCK_EX); 
};

FILE_APPEND works fine and i like the fact that all error gets stored in smtp.log and I can read the smtp.log file to check if the error causing my code to stop is a wrong password or too many login attempt ,

The problem is Append keeps adding to the same smtp.log which can be misleading , if the first password attempt was a wrong password and the second attempt generates too many login attempts error .. I would like to know the work around with this as FILE_OVERWRITE overwrites the whole log and leave just the last line "2019-07-28 12:58:07 2 SMTP Error: Could not authenticate." leaving out important information like "2019-07-28 12:58:07 2 SERVER -> CLIENT: 535 5.7.0 (#AUTH005) Too many bad auth attempts." which is what i need to tell my code the next line of action..

And i would like to know if there is a workaround to get only this SERVER -> CLIENT: 535 5.7.0 (#AUTH005) Too many bad auth attempts to file or stored to a variable for use.

$mail->SMTPDebug = 2; 
$mail->Debugoutput = function($str, $level) { 
file_put_contents('smtp.log', gmdate('Y-m-d H:i:s'). "\t$level\t$str
", FILE_APPEND | LOCK_EX); 
    };
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog