【问题标题】:Lumen with Mail - Unable to resolve NULL driver for [Illuminate\Mail\TransportManager]Lumen with Mail - 无法解析 [Illuminate\Mail\TransportManager] 的 NULL 驱动程序
【发布时间】:2019-03-08 03:37:39
【问题描述】:

我正在尝试从 Lumen 5.7 发送电子邮件,正如许多消息来源所提到的,我..

  1. 已将illuminate/mailguzzlehttp/guzzle 添加到我的应用程序中
  2. Laravel Repository 创建了“config/mail.php”和“config/services.php”
  3. 取消注释$app->withFacades();,注册Illuminate\Mail\MailServiceProvider::class并在bootstrap/app.php中的return $app;之前添加$app->configure('services');$app->configure('mail');
  4. 将mailgun设置添加到.env

    MAIL_DRIVER=mailgun

    MAILGUN_DOMAIN=ssss

    MAILGUN_SECRET=xxxxx

  5. 尝试发送电子邮件Mail::raw('Raw string email', function($msg) { $msg->to(['x@x.com']); $msg->from(['x@x.com']); });

但仍然收到此错误消息Unable to resolve NULL driver for [Illuminate\Mail\TransportManager].

附:这是我第一次使用 Lumen,我确实搜索了好几个小时来解决这个问题,但我做不到。

提前致谢。

【问题讨论】:

  • 我也有同样的问题,可以看到没有一个答案是正确的。你的问题解决了吗?
  • 好吧,我已经修好了....我愚蠢地将$app->configure('mail'); 放在return $app 之后,您的情况似乎不是这样。

标签: php email lumen


【解决方案1】:

如果配置文件夹在“app”文件夹中,则将“config”文件夹移至“主文件夹”。这个对我有用。 使用来自 Laravel (config/mail.php) 的邮件基础配置,对不起,你的话 ribrow :v

【讨论】:

  • 提供正确的问题解释。
【解决方案2】:

使用 Laravel 的邮件基础配置 (config/mail.php)

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Mail Driver
    |--------------------------------------------------------------------------
    |
    | Laravel supports both SMTP and PHP's "mail" function as drivers for the
    | sending of e-mail. You may specify which one you're using throughout
    | your application here. By default, Laravel is setup for SMTP mail.
    |
    | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses",
    |            "sparkpost", "log", "array"
    |
    */

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

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Address
    |--------------------------------------------------------------------------
    |
    | Here you may provide the host address of the SMTP server used by your
    | applications. A default option is provided that is compatible with
    | the Mailgun mail service which will provide reliable deliveries.
    |
    */

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Host Port
    |--------------------------------------------------------------------------
    |
    | This is the SMTP port used by your application to deliver e-mails to
    | users of the application. Like the host we have set this value to
    | stay compatible with the Mailgun e-mail application by default.
    |
    */

    'port' => env('MAIL_PORT', 587),

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

    /*
    |--------------------------------------------------------------------------
    | E-Mail Encryption Protocol
    |--------------------------------------------------------------------------
    |
    | Here you may specify the encryption protocol that should be used when
    | the application send e-mail messages. A sensible default using the
    | transport layer security protocol should provide great security.
    |
    */

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    /*
    |--------------------------------------------------------------------------
    | SMTP Server Username
    |--------------------------------------------------------------------------
    |
    | If your SMTP server requires a username for authentication, you should
    | set it here. This will get used to authenticate with your server on
    | connection. You may also set the "password" value below this one.
    |
    */

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    /*
    |--------------------------------------------------------------------------
    | Sendmail System Path
    |--------------------------------------------------------------------------
    |
    | When using the "sendmail" driver to send e-mails, we will need to know
    | the path to where Sendmail lives on this server. A default path has
    | been provided here, which will work well on most of your systems.
    |
    */

    'sendmail' => '/usr/sbin/sendmail -bs',

    /*
    |--------------------------------------------------------------------------
    | Markdown Mail Settings
    |--------------------------------------------------------------------------
    |
    | If you are using Markdown based email rendering, you may configure your
    | theme and component paths here, allowing you to customize the design
    | of the emails. Or, you may simply stick with the Laravel defaults!
    |
    */

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

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

];

别忘了安装依赖

composer require guzzlehttp/guzzle

【讨论】:

  • 感谢 ribrow 的回答,我已经尝试了我在问题中提到的建议。
【解决方案3】:

我遇到了同样的错误,并尝试了许多解决方案,但没有积极的结果。

我所做的是用这段代码替换 config/mail.php 并且它起作用了。使用 Lumen 6.0。

<?php
return [
  "driver" => "smtp",
  "host" => "smtp.mailtrap.io",
  "port" => 2525,
  "from" => array(
      "address" => "from@example.com",
      "name" => "Example"
  ),
  "username" => "user...",
  "password" => "....",
  "sendmail" => "/usr/sbin/sendmail -bs"
];

您可能要考虑的另一件事是确保您的照明/邮件包与 laravel/lumen-framework 版本匹配。 (在我的情况下为 6.0)

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2020-10-19
    • 2020-09-08
    • 1970-01-01
    • 2015-02-02
    • 2021-04-10
    • 2019-07-14
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多