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