It sounds like you've already covered most of the common pitfalls, so let's dig a bit deeper. Here are some additional steps and checks that might help resolve the issue:
1. Double-Check the Deployed .env File
Sometimes, the .env file you’re editing isn’t the one being used by your application (especially if you have multiple deployment environments or symlinked directories). SSH into your production server and run:
cat /path/to/your/project/.env | grep MAIL_
Make sure the values shown are the new ones.
2. Clear the Config Cache (Again)
Laravel caches the configuration, and sometimes config:clear alone doesn’t do the trick. Try running:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Then, restart your web server and PHP-FPM again.
3. Debug the Actual Config Values
Add a temporary debug route to check what Laravel is actually using at runtime:
Route::get('/mail-debug', function () {
return config('mail.mailers.smtp');
});
Visit /mail-debug in your browser. This will show you the SMTP config Laravel is using. If you still see the old values, the config cache is likely not clearing, or the wrong .env file is being loaded.
4. Check for Environment Variable Overrides
- Server Environment Variables: Sometimes, environment variables set at the server (e.g., in Apache’s
.htaccess, Nginx config, or systemd service files) can override.envvalues. Runprintenv | grep MAIL_on your server to see if any are set. - Deployment Tools: If you use Envoyer, Forge, or similar, check their environment variable management.
5. Queue Workers
If you’re sending emails via queued jobs, remember that queue workers may have been started before the .env change and are still using the old config. Restart all queue workers:
php artisan queue:restart
6. Double-Check for Multiple .env Files
Rare, but sometimes there are multiple .env files (e.g., .env.production, .env.backup). Ensure you’re editing the correct one.
7. Check for Custom Mail Drivers
If you have a custom mail driver or a package that overrides the mail configuration, check your config/services.php and any service providers for hardcoded values.
8. Test with php artisan tinker
Try sending a test email from Tinker to see if the new config is picked up:
php artisan tinker
Then:
\Mail::raw('Test', function($msg) { $msg->to('[email protected]'); });
Summary Checklist
- Confirm
.envchanges are on the correct server and directory - Run
php artisan config:clearandphp artisan config:cache - Restart web server, PHP-FPM, and queue workers
- Debug config at runtime
- Check for server-level environment variable overrides
If after all this, the problem persists, please share the output of your /mail-debug route and any relevant server environment variable dumps. That will help narrow down the issue further!