#3161·PHPMailer

Improve Exception message on SMTP Authentication failure

Author: lm-cmxkonzepteCreated May 12, 2025Updated May 13, 2025

Problem description

Anytime when an authentication failure happens, PHPMailer throws an Exception (when Exceptions are enabled) with a generic error message. This happens in PHPMailer.php:2327:

if (
    $this->SMTPAuth && !$this->smtp->authenticate([…])
) {
    throw new Exception($this->lang('authenticate'));
}

It would be a lot more helpful if the error message included the response the SMTP server gave. This can be done just by doing this instead:

if (
    $this->SMTPAuth && !$this->smtp->authenticate([…])
) {
    throw new Exception($this->getSmtpErrorMessage('authenticate'));
}

It seems such an obvious solution, is the reduced error message maybe intentional, e. g. for some security reasons? If it isn’t, I‘m happy to make a pull request with this change.