PHPMailer - SMTP ERROR: Password command failed when send mail from my server
This error message typically indicates that the SMTP server is unable to authenticate the provided login credentials for the email account being used to send the email.
This error message typically indicates that the SMTP server is unable to authenticate the provided login credentials for the email account being used to send the email. This could be caused by a number of things, such as an incorrect password, an incorrect username, or issues with the server's authentication settings.
To troubleshoot this issue, you should first verify that the login credentials being used by PHPMailer are correct. You may also want to try logging in to the email account using the same credentials via a web interface to ensure that the account is active and that the login information is correct.
To see the exact SMTP conversation and pinpoint the failure, enable PHPMailer's debug mode by adding `$mail->SMTPDebug = 2;` before sending the email. This will output the full SMTP handshake to the browser or console.
If the login credentials are correct, then you should check the SMTP server's authentication settings. Make sure that the server is configured to allow SMTP authentication, and that the specific login method being used by PHPMailer (e.g. PLAIN, LOGIN, CRAM-MD5, etc.) is supported.
If you are still unable to resolve the issue, you may want to check the server's log files for more detailed information about the error. This could provide additional clues as to what is causing the problem.
Below is a minimal example of a correct SMTP configuration in PHPMailer:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'your_app_password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;Note that modern email providers like Gmail and Outlook often require App Passwords or specific SMTP settings due to two-factor authentication (2FA) and security policies. Ensure your credentials match these requirements.
Other things to check:
- Check the email account is not blocked by the email service provider.
- Check the email account is not out of quota.
- Check the IP address or domain of your server is not blacklisted.
- Consider using a different SMTP host, if possible.