带邮件的流明-无法解析[Illuminate \ Mail \ TransportManager]的NULL驱动程序

时间:2018-10-03 00:07:22

标签: php email lumen

我正尝试从Lumen 5.7发送电子邮件,因此,正如许多消息来源所述,我..

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

    MAIL_DRIVER = mailgun

    MAILGUN_DOMAIN = ssss

    MAILGUN_SECRET = xxxxx

  5. 试图发送电子邮件.env

但仍然收到此错误消息Mail::raw('Raw string email', function($msg) { $msg->to(['x@x.com']); $msg->from(['x@x.com']); });

P.S。这是我第一次接触Lumen,我做了很多小时的努力来解决这个问题,但是我做不到。

谢谢。

3 个答案:

答案 0 :(得分:1)

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

我所做的就是用这段代码替换config / mail.php,并且可以正常工作。使用流明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"
];

您可能要考虑的另一件事是,确保您的illuminate / mail软件包与laravel / lumen-framework版本匹配。 (我的情况是6.0)

答案 1 :(得分:0)

使用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

答案 2 :(得分:0)

如果config文件夹位于“ app”文件夹中,则将“ config”文件夹移至“主文件夹”。这个对我有用。 使用来自Laravel(config / mail.php)的邮件基础配置,很抱歉让您大吃一惊:v