Laravel 5.5使用Yahoo SMTP发邮件报错550请求失败求助
Hey there, I’ve run into this exact issue before with Yahoo SMTP, so let’s break down the most common fixes to get your emails sending smoothly again. Since your Gmail setup works fine, the problem is almost certainly related to Yahoo’s specific security requirements or configuration details.
1. Use an App Password instead of your regular Yahoo password
Yahoo enforces strict security measures, especially if you have two-factor authentication (2FA) enabled on your account. Your regular password won’t work for SMTP access—you need to generate a dedicated App Password:
- Log into your Yahoo account, go to Account Security settings.
- Look for the App Passwords option (you might need to verify your identity first).
- Select the app type as Mail and your device (or just choose "Other" and name it "Laravel").
- Generate the password, then copy it into your
.envfile’sMAIL_PASSWORDfield.
2. Ensure your sender address matches your Yahoo username
Yahoo requires that the "from" email address in your mail matches the SMTP username you’re using. Update your sendMail function to explicitly set the from address:
public function sendMail(){ $data = []; Mail::send('welcome', $data, function($message) { $message->from('example@yahoo.com', 'Your Name') // Match your MAIL_USERNAME ->to('john.doe@outlook.com', 'John Doe') ->subject('Welcome!'); }); return 'ok'; }
You can also set this globally by adding these lines to your .env:
MAIL_FROM_ADDRESS=example@yahoo.com MAIL_FROM_NAME="Your Name"
3. Double-check your SMTP configuration
While your current .env settings look mostly right, let’s confirm and tweak if needed:
MAIL_DRIVER=smtp MAIL_HOST=smtp.mail.yahoo.com MAIL_PORT=587 MAIL_USERNAME=example@yahoo.com MAIL_PASSWORD=your-generated-app-password MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=example@yahoo.com MAIL_FROM_NAME="Your Name"
If port 587 with TLS still fails, try switching to port 465 with SSL:
MAIL_PORT=465 MAIL_ENCRYPTION=ssl
4. Clear Laravel’s configuration cache
After updating your .env file, Laravel might still be using cached old settings. Run these commands in your terminal:
php artisan config:clear php artisan cache:clear
5. Verify Yahoo’s third-party access settings
Make sure your Yahoo account allows third-party apps to access it:
- Go to Account Security > Allow apps that use less secure sign-in (note: this option might be hidden if you have 2FA enabled, which is why using an App Password is the more secure and reliable approach).
If none of these steps work, double-check that your recipient’s email address is valid and not marked as spam by Yahoo. Also, confirm that your Yahoo account hasn’t been restricted for any reason (like unusual login attempts).
内容的提问来源于stack exchange,提问作者Ehsan Ali

