laravel 无法解析 [Illuminate\Mail\TransportManager] 的 NULL 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50302095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to resolve NULL driver for [Illuminate\Mail\TransportManager]
提问by BrickZ28
I am getting this error InvalidArgumentException Unable to resolve NULL driver for [Illuminate\Mail\TransportManager] on Laravel 5.6 and I'm having this issue both on my local machine and on the test website the internet. I started off using just gmail with smtp and was getting some login problems, so i then came across mailgun and set everything up with that. I have my .env file set up (the test website shows driver as mailgun properly)
我收到此错误 InvalidArgumentException Unable to resolve NULL driver for [Illuminate\Mail\TransportManager] on Laravel 5.6 我在本地机器和测试网站上都遇到了这个问题。我开始只使用带有 smtp 的 gmail 并且遇到了一些登录问题,所以我遇到了 mailgun 并用它设置了一切。我已经设置了 .env 文件(测试网站正确地将驱动程序显示为 mailgun)
MAIL_DRIVER=log
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=USERNAME
MAIL_PASSWORD=PWD
MAIL_ENCRYPTION=tls
My config/email is as follows
我的配置/电子邮件如下
'mailgun' => [
'domain' => 'domain',
'secret' => 'key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
'host' => env('smtp.mailgun.org', 'smtp.mailgun.org'),
'port' => env('587', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('uname'),
'password' => env('pwd'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
config/services is
配置/服务是
'mailgun' => [
'domain' => env('domain'),
'secret' => env('key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
],
'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'),
],
];
Ever since adding this stuff ive gotten the problem. Ive was getting output to the log file and as i mentioned earlier when using gmail smtp i did not get this driver error. I have tried the laravel docs using maiables and that didnt help. I used this link https://scotch.io/tutorials/easy-and-fast-emails-with-laravel-5-3-mailablesas a guide and even then i got the same error. Ive done a dd on the Route
自从添加这些东西以来,我就遇到了问题。我正在获取日志文件的输出,正如我之前提到的,在使用 gmail smtp 时,我没有收到此驱动程序错误。我已经使用 maiables 尝试了 laravel 文档,但没有帮助。我使用此链接https://scotch.io/tutorials/easy-and-fast-emails-with-laravel-5-3-mailables作为指南,即使这样我也遇到了同样的错误。我在路线上做了一个 dd
Route::get('test', function(){
dd(Config::get("mail"));
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{dd(Config::get("mail"));
$message->to('[email protected]');
});
});
with the following results
结果如下
array:9 [▼
"mailgun" => array:2 [▼
"domain" => "domain"
"secret" => "key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
]
"host" => "smtp.mailgun.org"
"port" => 587
"from" => array:2 [▼
"address" => "[email protected]"
"name" => "Example"
]
"encryption" => "tls"
"username" => null
"password" => null
"sendmail" => "/usr/sbin/sendmail -bs"
"markdown" => array:2 [▼
"theme" => "default"
"paths" => array:1 [?]
]
]
Admitantly I'm new to Laravel so i was pretty eager to try to resolve this, as that is the best way to learn, but with even google I personally wasnt finding alot of help so i reach out to some of the experts here on SO. Thank you in advance.
诚然,我是 Laravel 的新手,所以我非常渴望尝试解决这个问题,因为这是最好的学习方式,但即使是谷歌,我个人也没有找到很多帮助,所以我联系了这里的一些专家。 . 先感谢您。
采纳答案by DevK
If you want to use Mailgun you should change to this in your .env
:
如果你想使用 Mailgun 你应该在你的.env
:
MAIL_DRIVER=mailgun
Which will tell Laravel to use this config from config/services
:
这将告诉 Laravel 使用以下配置config/services
:
'mailgun' => [
'domain' => 'domain',
'secret' => 'key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
Edit:
编辑:
Change your config/email.php
to this. Copy paste replace everything in your current config and the error should be resolved. You should do the same for config/services.php
- copy from here.
把你的config/email.php
改成这个。复制粘贴替换当前配置中的所有内容,错误应该得到解决。你应该config/services.php
从这里做同样的 for -copy 。
Reason: you deleted the 'driver' => env('MAIL_DRIVER', 'smtp'),
line from your config and Laravel is unable to resolve the driver.
原因:您'driver' => env('MAIL_DRIVER', 'smtp'),
从配置中删除了该行,而 Laravel 无法解析驱动程序。
Even if you just add this line you'll run into more errors because of these lines:
即使你只是添加这一行,你也会因为这些行而遇到更多错误:
'username' => env('uname'),
'password' => env('pwd'),
The first argument for env(..)
function is which line in .env
file to look for the variable. The 2nd is the default value if the variable is not found in the .env
. You don't have variables uname
and pwd
in your env (at least from what you've shown). And you don't provide the default value either.
env(..)
function的第一个参数是在.env
文件中查找变量的哪一行。如果在.env
. 您没有变量uname
并且pwd
在您的环境中(至少从您所展示的内容来看)。而且您也不提供默认值。
Long story short, don't edit your mail config, edit the variables in the .env
file instead.
长话短说,不要编辑您的邮件配置,.env
而是编辑文件中的变量。