luisdalmolin / laravel-mandrill-driver

Mandrill mail driver for Laravel for version 6+
MIT License
79 stars 38 forks source link

Unsupported mail transport [mandrill] (Laravel 7.*) #9

Closed Hakeemmidan closed 4 years ago

Hakeemmidan commented 4 years ago

Laravel version: 7.23.0 I get this error when I try to run php artisan queue:listen or php artisan schedule:run, which both have mail sending in them.

Error:

Unsupported mail transport [mandrill].

  at vendor/laravel/framework/src/Illuminate/Mail/MailManager.php:172
    168|             return call_user_func($this->customCreators[$transport], $config);
    169|         }
    170| 
    171|         if (trim($transport) === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
  > 172|             throw new InvalidArgumentException("Unsupported mail transport [{$transport}].");
    173|         }
    174| 
    175|         return $this->{$method}($config);
    176|     }

      +20 vendor frames 
  21  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(LaravelMandrill\MandrillServiceProvider))

      +5 vendor frames 
  27  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

mail.php:

'driver' => env('MAIL_DRIVER', 'mandrill'),
...

'mailers' => [
      'smtp' => [
          'transport' => 'smtp',
          'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
          'port' => env('MAIL_PORT', 587),
          'encryption' => env('MAIL_ENCRYPTION', 'tls'),
          'username' => env('MAIL_USERNAME'),
          'password' => env('MAIL_PASSWORD'),
          'timeout' => null,
          'auth_mode' => null,
      ],

      'ses' => [
          'transport' => 'ses',
      ],

      'mailgun' => [
          'transport' => 'mailgun',
      ],

      'postmark' => [
          'transport' => 'postmark',
      ],

      'sendmail' => [
          'transport' => 'sendmail',
          'path' => '/usr/sbin/sendmail -bs',
      ],

      'log' => [
          'transport' => 'log',
          'channel' => env('MAIL_LOG_CHANNEL'),
      ],

      'array' => [
          'transport' => 'array',
      ],
      'mandrill' => [ // added this code as requested
        'transport' => 'mandrill',
      ],
    ],

And I believe that both services.php and .env are both set up correctly. Any ideas?

therobfonz commented 4 years ago

This line might be the issue

'driver' => env('MAIL_DRIVER', 'mandrill'),

In Laravel 7, driver changed to default. Might as well update the ENV variable while you are at it to the new one.

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

I would also check and try and run php artisan package:discover after as it might have choked on that config being wrong since it looks like the service provider didn't auto-boot (why its saying the transport doesn't exist)

Hakeemmidan commented 4 years ago

Thank you for your response.

Changing 'driver' to 'default', and 'MAIL_DRIVER' to 'MAIL_MAILER' doesn't fix it. It gives the same error.

Running php artisan package:discover also gives the same error.

I tried to run php artisan cache:clear and php artisan config:clear to see if that was the issue, but I got the same errors there too.

therobfonz commented 4 years ago

Check your services config file (if you think it is good, paste what you have here for mandrill). I would dd($config) within the service provider and see what it finds. If the config is empty, that might cause an error.

Hakeemmidan commented 4 years ago

So my services config file (services.php) looks something like this:

<?PHP
return [
     // ...
     'mandrill' => [
        'secret' => env('MANDRILL_SECRET', 'exampleSecretString'),
    ],
    // ...
];

By service provider, do you mean AppServiceProvider.php? If so, I tried doing dd(config())) (since $config is not defined anywhere in the project), and I got this:

    // ...
    "mail" => array:10 [
      "driver" => "mandrill"
      "host" => "mtp.mandrillapp.com"
      "port" => 587
      "from" => array:2 [
        "address" => "example@example.com"
        "name" => "Example"
      ]
      "encryption" => "tls"
      "username" => "example@example.com"
      "password" => "examplePassword"
      "sendmail" => "/usr/sbin/sendmail -bs"
      "markdown" => array:2 [
        "theme" => "default"
        "paths" => array:1 [
          0 => "/var/www/resources/views/vendor/mail"
        ]
      ]
      "log_channel" => null
    ]
   // ...

Side note: I tried changing all variables that have the word mandrill across the project directory to something else and I still got the "Unsupported mail transport [mandrill]." error. This made me wonder if it's something on the package or Laravel side. Do you know if anyone has used it with Laravel v7.* (or v7.23.0 more specifically) before?

therobfonz commented 4 years ago

I unfortunately no longer work for the company where I used this package heavily, but have a v7 freelance project that will use it in the next few weeks. It is installed on it and I am not getting the errors you speak of though.

Was this project you are using it on a recent upgrade from Laravel 6? There might be something missing. Obvious question, but you are using v2.0+ of the package, right?

Hakeemmidan commented 4 years ago

I see. Yes, actually I just upgraded from Laravel 6 to Laravel 7. So it may be coming from there. I'll look through their upgrade guide again to see if there is something I'm missing. If I find a solution, I'll post it here.

And yes, I'm using v2.0 of the package.

Hakeemmidan commented 4 years ago

It may be related to compatibility with "fedeisas/laravel-mail-css-inliner" Laravel package. In this comment, the comment-author mentioned the exact same error, but for SparkPost email client. Here's a fix that someone suggested, though it hasn't worked for me.

Update: Following this comment's suggestion actually worked. I just forgot to run composer dump-autoload.