Laravel 6发送邮件报错:Unable to resolve NULL driver for [Illuminate\Mail\TransportManager]
Let's walk through this issue step by step— that NULL driver error pops up when Laravel can't figure out which mail transport to use, and the root cause here is a mismatch between your environment variables and Laravel's current configuration requirements.
Key Issue: Outdated Environment Variable Name
Starting with Laravel 7+, the framework switched from using MAIL_DRIVER to MAIL_MAILER as the environment variable for specifying the default mailer. Your .env file still uses the old MAIL_DRIVER variable, which means Laravel can't pick up the correct default mailer, resulting in the NULL driver error.
Step-by-Step Fixes
Update your .env file's variable name
Replace the oldMAIL_DRIVERline with the new variable name:# Replace this: MAIL_DRIVER=smtp # With this: MAIL_MAILER=smtpKeep the rest of your mail configuration as is—your localhost:1025 setup (likely for MailHog or a similar local mail testing tool) is valid:
MAIL_HOST=localhost MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=myemail@domain.com MAIL_FROM_NAME="${APP_NAME}"Clear Laravel's configuration cache
Laravel caches config files for performance, so you need to clear the old cached config to apply the new variable:php artisan config:clear php artisan cache:clearVerify your mail.php configuration
Double-check that yourconfig/mail.php'sdefaultvalue correctly references theMAIL_MAILERenv variable (which it does in your provided code):'default' => env('MAIL_MAILER', 'smtp'),This ensures Laravel uses the
smtpmailer from yourmailersarray when the env variable is set correctly.Check your BCC configuration (optional but recommended)
In your send code, you're pullingapp('config')->get('mail')['bcc']—make sure you have abcckey defined in yourconfig/mail.phpto avoid passing a null value:// Add this to config/mail.php 'bcc' => env('MAIL_BCC', ''),Then set the corresponding env variable if needed:
MAIL_BCC=your-bcc-email@domain.com
Quick Test to Validate
To rule out issues with your Get_a_quote Mailable class, run a simple raw mail test first:
Mail::raw('Test email content', function ($message) { $message->to('drako@domain.com') ->subject('Laravel Mail Test'); });
If this works, the problem was either the env variable mismatch or a bug in your Mailable class.
内容的提问来源于stack exchange,提问作者Juliver Galleto

