php - 函数 Illuminate\Support\Manager::createDriver() 的参数太少,在 framework/src/Illuminate/Support/Manager.php 中传递了 0

标签 php laravel laravel-5

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

Symfony\Component\Debug\Exception\FatalThrowableError Type error: Too few arguments to function Illuminate\Support\Manager::createDriver(), 0 passed in public_html/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 88 and exactly 1 expected



.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'),
        ],
    ],

];

最佳答案

首先:确保您在配置文件夹中设置了 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=

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

原因

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

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

希望这可以帮助

关于php - 函数 Illuminate\Support\Manager::createDriver() 的参数太少,在 framework/src/Illuminate/Support/Manager.php 中传递了 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48297352/

相关文章:

php如何正确使用inotify实例进行目录监控

php - file_get_contents 是多行吗?

PHP/MySQL : Storing and retrieving UUIDS

node.js - Laravel echo、socket.io 和 laravel-echo-server 将无法工作

laravel - 如何从迁移创建 Laravel 模型?

php - 关于关系的 laravel 订单查询

php - Laravel 5.2 - 将值插入用户列不起作用

php - 无法在docker容器中安装soap

php - fatal error 异常类 'contact' 未找到 laravel 5

php - 拉拉维尔 5.7 : Detecting duplicates in a collection based on multiple keys (done) but how to move dupes to another collection?