Laravel部署共享主机后发送邮件遇550未授权IP错误求助
Hey there, sorry to hear you're stuck with this email sending issue! Let's break down what's happening and how to fix it.
Why This Error Happens
The 550-Hosting ACL: unauthorized IP error means that the outgoing IP address of your shared hosting server (67.225.178.60) isn't authorized to send emails using your Gmail SMTP credentials. Gmail checks the source IP of SMTP requests to block unauthorized use, and your shared host's IP isn't on its trusted list—even though your local server's IP works perfectly.
Step-by-Step Solutions
1. Use a Google App Password (If 2FA is Enabled)
If you have two-factor authentication turned on for your Gmail account, your regular password won't work for SMTP connections. You need a dedicated App Password:
- Log into your Google Account, head to Security > App Passwords (you might need to verify your identity first).
- Select "Mail" as the app and "Other (custom name)" as the device (e.g., "My Laravel Shared Host").
- Generate the 16-character password, then replace the
MAIL_PASSWORDin your.envfile with this code.
2. Authorize Your Shared Host's IP in Google
Google might be automatically blocking your host's IP. Here's how to unblock it:
- Check your Gmail account's Recent Security Activity (under Security settings). Look for a login attempt from the IP 67.225.178.60.
- If you see a "blocked" notification, click "Yes, that was me" to authorize the IP.
3. Switch to Your Shared Host's Native SMTP Server
Using your host's built-in email service avoids IP authorization issues entirely. Most shared hosts (like those with cPanel) provide their own SMTP details:
- Update your
.envconfig to something like this:MAIL_DRIVER=smtp MAIL_HOST=mail.yourdomain.com # Check your host's docs for the correct SMTP address MAIL_PORT=587 MAIL_USERNAME=your-host-email@yourdomain.com MAIL_PASSWORD=your-host-email-password MAIL_ENCRYPTION=tls - This uses your host's own email server, so no external IP restrictions apply.
4. Verify Shared Host's SMTP Port Access
Some shared hosts block outbound SMTP ports (like 465 or 587) by default. Reach out to your hosting provider's support team to confirm:
- Are ports 465/587 open for your account?
- Do they have any email sending limits or restrictions you need to follow?
Final Check: Clear Laravel Cache
After updating your .env file, make sure Laravel picks up the new config by running these commands via SSH (or your host's terminal):
php artisan config:clear php artisan cache:clear
内容的提问来源于stack exchange,提问作者Cristian cruz benel

