Email Not Sending
Step-by-step troubleshooting for email delivery issues.
Step 1: Check the Basics
# Check .env SMTP settings
grep MAIL_ .env
Verify:
MAIL_MAILER=smtp(notlogornull)MAIL_HOSTis correctMAIL_PORTis correct (587 for TLS, 465 for SSL)MAIL_USERNAMEandMAIL_PASSWORDare filledMAIL_ENCRYPTION=tls(orssl)
Step 2: Test via Admin Panel
- 前往 Admin > 设置 > Email
- Click Send Test Email
- Check the error message if it fails
Step 3: Test via Command Line
php artisan tinker
Mail::raw('Test', function ($m) {
$m->to('[email protected]')->subject('Test');
});
Check storage/logs/laravel.log for errors.
常见问题
| Issue | Solution |
|---|---|
| "Connection timed out" | Port 587/465 blocked by hosting. Try port 2525 or contact host. |
| "Authentication failed" | Wrong username/password. For Gmail, use App Password. |
| "Certificate verify failed" | Old PHP. Try 'verify_peer' => false in config/mail.php mailer options. |
| Emails going to spam | Add SPF, DKIM, and DMARC DNS records. |
| Emails delayed | Using QUEUE_CONNECTION=database? Ensure queue worker is running. |
| No error but no email | Using MAIL_MAILER=log? Emails are being logged, not sent. Check storage/logs/laravel.log. |
Using MAIL_MAILER=log for Debugging
Set MAIL_MAILER=log in .env to capture all emails in the log file instead of sending them. Useful for verifying email content without affecting real recipients.