Yii2 SwiftMailer发送邮件失败:SMTP 535认证错误求助
Let's work through your issue step by step—here's what you need to check and fix:
1. Don't be misled by the Google support link in the error
The error message references Google's support page, but that's just a generic hint many SMTP providers use when rejecting credentials. This doesn't mean your app is still connecting to Google's SMTP server; it's just part of Yahoo's standard error response template.
2. Verify your Yahoo SMTP configuration & account settings
Even though you enabled less secure apps and tried an app password, double-check these critical details:
- App Password requirements: Yahoo requires you to have two-step verification (2SV) enabled on your account before you can generate a valid app password. If you didn't turn on 2SV first, the app password won't work at all.
- Correct app password usage: When generating an app password for your Yii app, make sure you copy the full, unmodified string (no spaces, no extra characters) into your
passwordconfig field. - Double-check SMTP parameters: Your current config looks right on paper, but confirm:
hostis exactlysmtp.mail.yahoo.comportis587withencryptionset totlsusernameis your full Yahoo email address (you have this correct, but typos are easy to miss!)
3. Rule out Yii application caching (not Apache)
Apache does not cache SMTP credentials—this is a common misconception. However, Yii might be caching your old Google SMTP configuration if you have config caching enabled. To fix this:
- Flush Yii's application cache using the console command:
./yii cache/flush-all - Alternatively, manually delete the cache files in your app's
runtime/cachedirectory to force Yii to load the new config.
4. Validate your SMTP connection outside of Yii
To confirm the issue isn't with your code, test the Yahoo SMTP connection directly using a tool like Swaks or Telnet:
- Using Telnet:
telnet smtp.mail.yahoo.com 587 EHLO localhost AUTH LOGIN # Enter your base64-encoded email address # Enter your base64-encoded app password
If this fails, the problem is definitely with your Yahoo account settings, not your Yii code. If it works, then you know the issue is in how Yii is loading or using the config.
5. Final checks
- Ensure you've logged into your Yahoo account via the web recently to confirm there are no pending security alerts (Yahoo sometimes blocks new app connections until you verify the login is legitimate).
- If you're using a regional Yahoo domain (like
yahoo.co.uk), confirm the SMTP host matches (it should still besmtp.mail.yahoo.com, but double-check for regional variations).
内容的提问来源于stack exchange,提问作者Valik Tralik

