【问题标题】:Too few arguments to function Illuminate\Support\Manager::createDriver(), 0 passed in framework/src/Illuminate/Support/Manager.php函数 Illuminate\Support\Manager::createDriver() 的参数太少,在 framework/src/Illuminate/Support/Manager.php 中传递了 0
【发布时间】:2018-06-26 02:41:43
【问题描述】:

我正在使用 smtp 协议通过 mailtrap 发送邮件。它在本地主机中运行良好,但出现错误。

Symfony\Component\Debug\Exception\FatalThrowableError 类型错误:太 函数 Illuminate\Support\Manager::createDriver() 的几个参数, 0 传入 public_html/vendor/laravel/framework/src/Illuminate/Support/Manager.php 在第 88 行,预期正好是 1

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=name
MAIL_PASSWORD=pass
MAIL_ENCRYPTION=null

邮件.php

<?php
return [

    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailtrap.org'),
    'port' => env('MAIL_PORT', 2525,
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

【问题讨论】:

  • 您不应在 StackOverflow 问题中发布您的凭据。
  • 谢谢摩根莱恩
  • 通过邮件'driver' =&gt; 'smtp'试试这个,
  • 它不起作用
  • 试试php artisan vendor:publishcomposer dump-autoload

标签: php laravel laravel-5


【解决方案1】:

首先:确保您在配置文件夹中设置了 mail.php 和 services.php

分别如下:

邮件.php

 <?php
    return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.org'),
'port' => env('MAIL_PORT', 2525,
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',

'markdown' => [
    'theme' => 'default',

    'paths' => [
        resource_path('views/vendor/mail'),
    ],
],

];

还有services.php(注意这包括mailgun配置)

<?php

return [

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'secret' => env('MAILGUN_SECRET'),
],

'ses' => [
    'key' => env('SES_KEY'),
    'secret' => env('SES_SECRET'),
    'region' => 'us-east-1',
],

'sparkpost' => [
    'secret' => env('SPARKPOST_SECRET'),
],

'stripe' => [
    'model' => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

];

将此添加到您的 boostrap/app/php 文件中

$app->configure('mail'); // this is to configure the mail
$app->configure('services'); // and to configure the services
//$con = env('MAIL_DRIVER');

// dd($con);

dd(config('mail')); // this is to print the mail configuration so you can know what mail configuration are being read.

return $app;

在终端中运行php artisan serve 只是为了查看邮件配置的内容。

请注意 我注意到简单的解决方法是使用凭据更新/修改 .env 文件(以 gmail smtp 服务器为例)

MAIL_DRIVER_=smtp  (instead of MAIL_DRIVER, update it the mail.php)
MAIL_HOST_=smtp.gmail.com (instead of MAIL_HOST)
MAIL_PORT_=587
MAIL_USERNAME=youremail@domain.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls

MAILGUN_DOMAIN=
MAILGUN_SECRET=

之后,如果您已经在运行您的服务器。杀死它并重新运行它。这应该可以解决您的错误,

原因

由于我无法解释的原因,某些邮件配置参数在我应用上述更改之前没有反映。

其次,我后来将 .env 设置更改为原始名称,消除了额外的“_”并更新了 mail.php,并且不得不杀死已经运行的服务器并重新运行它,然后才能反映并运行良好或正常工作!.

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 2017-09-10
    • 1970-01-01
    • 2016-02-11
    • 2019-11-01
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    相关资源
    最近更新 更多