Authenticator LOGIN returned Expected response code 235 but got code "535"
When you deploy a Laravel application from localhost to a production environment, the most common breakage involves email delivery. The error Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data" is a definitive signal: the SMTP server rejected your credentials.
The fact that this works on localhost but fails in production usually points to one of three culprits: environment variable leakage, strict security policies enforced by the provider (specifically Gmail), or incorrect port/encryption combinations. Let's dissect the specific configuration provided and identify where the failure occurs.
The "Incorrect Authentication Data" Trap
The error code 535 indicates a generic authentication failure. In the context of Google Workspace or personal Gmail accounts, this almost exclusively means one of two things:
- App Passwords are Required: If Two-Factor Authentication (2FA) is enabled on the user account, the standard
MAIL_PASSWORDfield will not accept the regular login password. Google blocks application-level access to prevent phishing attacks. - Account Security Restrictions: Even without 2FA, Google often disables third-party SMTP access for free accounts (
@gmail.com) unless an App Password is explicitly generated.
The source code attempts to authenticate using smtp.googlemail.com. While this hostname works, it does not bypass Google's security layers. If the password in your .env file is the standard login password and 2FA is active, Google returns code 535 immediately upon receiving the credentials via the LOGIN or PLAIN auth methods.
Environment Configuration vs. Production Reality
Your .env configuration specifies MAIL_PORT=465 and MAIL_ENCRYPTION=ssl. This is technically valid; port 465 uses implicit TLS, where the connection is encrypted immediately upon opening. However, there is a critical nuance often missed during deployment:
Environment Variable Leakage.
On localhost, you might have your .env file open in an editor where you can clearly see the password. In production, if your CI/CD pipeline or server configuration accidentally exposes this file to version control (GitHub, GitLab), or if the variable is not strictly scoped, security headers might differ. While this doesn't directly cause a 535 error, it is a best practice violation that often accompanies these failures.
More importantly, ensure that MAIL_FROM_ADDRESS matches the domain you are using for authentication. You have set MAIL_FROM_ADDRESS=noreply@lifelove.com. If your Gmail account has "Sender signatures" or specific filters that block sending from non-Gmail domains without verification, this could trigger stricter checks, though it typically results in a bounce rather than an immediate auth failure. The primary issue remains the credential format.
Resolving the Authentication Failure
To fix the 535 Incorrect authentication data error with Gmail, you must switch to App Passwords. Follow this process:
- Log into your Gmail account via a browser.
- Navigate to Security settings.
- Ensure 2-Step Verification is enabled.
- Go to the App passwords section.
- Generate a new app password for "Mail" or "Other (Custom name)".
Update your .env file with this 16-character generated password:
MAIL_PASSWORD=abcd efgh ijkl mnop
Addressing the SSL Configuration
You included this block in config/mail.php:
'stream' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
],
Do not use this in production. Disabling peer verification (verify_peer set to false) tells your application to ignore the server's SSL certificate. This is a significant security risk because it allows man-in-the-middle attacks. If you are using port 465 with ssl, you should rely on default behavior where Laravel verifies the certificate against known authorities. Only disable verification if you are connecting to an internal, self-signed SMTP server (like Postfix or Exim) that you fully control. For Gmail, removing this stream configuration block is the recommended approach.
Final Verification
If switching to App Passwords does not resolve the issue, check the exact MAIL_HOST. Some providers require smtp.gmail.com instead of smtp.googlemail.com, though the latter usually redirects correctly. Also, ensure you are not using port 587 with encryption set to tls unless you explicitly intend to use STARTTLS. Port 465 is generally safer for implicit SSL connections, provided your firewall allows traffic on that specific port in your hosting environment.
Once the App Password is applied and the SSL verification settings are reverted to secure defaults, the application should successfully authenticate and send emails without triggering code 535.
