You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 6发送邮件报错:Unable to resolve NULL driver for [Illuminate\Mail\TransportManager]

Fixing "Unable to resolve NULL driver for [Illuminate\Mail\TransportManager]" in Laravel Mail

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

  1. Update your .env file's variable name
    Replace the old MAIL_DRIVER line with the new variable name:

    # Replace this:
    MAIL_DRIVER=smtp
    # With this:
    MAIL_MAILER=smtp
    

    Keep 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}"
    
  2. 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:clear
    
  3. Verify your mail.php configuration
    Double-check that your config/mail.php's default value correctly references the MAIL_MAILER env variable (which it does in your provided code):

    'default' => env('MAIL_MAILER', 'smtp'),
    

    This ensures Laravel uses the smtp mailer from your mailers array when the env variable is set correctly.

  4. Check your BCC configuration (optional but recommended)
    In your send code, you're pulling app('config')->get('mail')['bcc']—make sure you have a bcc key defined in your config/mail.php to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:02:50