douzhao9608 2017-09-15 04:04
浏览 153
已采纳

在Lumen发送邮件

I've read a lot of guides and questions and answers on how to send mail using Lumen. I've tried a lot of these suggestions.

However, I still get this error:

(1/1) FatalThrowableError
Type error: Too few arguments to function Illuminate\Support\Manager::createDriver(), 0 passed in /var/www/monitor/vendor/illuminate/support/Manager.php on line 88 and exactly 1 expected

Full stack trace here.

This is my controller:

use Illuminate\Support\Facades\Mail;

public function check() {
    $response = $this->getResponse();
    if ($response) {
        if ($this->isAlive($response->state)) {
            $user = new \stdClass();
            $user->email = '****@gmail.com';
            $user->name = 'Albert';
            Mail::raw('test', function($mail) use ($user) {
                $mail->to($user->email, $user->name)->subject('Test Subject');
            });
            // I've also tried Mail::send() but no luck
            echo 'System is fine';
        } else {
            echo 'System has issues';
        }
    } else {
        echo 'Error connecting';
    }
}

I have uncommented and added the following lines to my bootstrap/app.php:

$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);
$app->register(Illuminate\Mail\MailServiceProvider::class);

I've got the following in my .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailaddress@gmail.com
MAIL_PASSWORD=mygmailpassword
MAIL_ENCRYPTION=tls

Am I missing something?

  • 写回答

1条回答 默认 最新

  • duanba4254 2017-09-15 06:42
    关注

    The problem is that the mail manager depends on the mail configuration, and Lumen has not included the mail configuration by default since 5.1. If you are using Lumen > 5.1, you will need to add your own mail config file, and update your bootstrap file to load the configuration file.

    First, create a config directory next to your app directory.

    Next, add a mail.php file in your new config directory. You can copy the contents from the default Laravel install that matches the Lumen version you are using (for example, if you're using Lumen 5.4, just copy the mail.php config file from Laravel 5.4).

    Finally, in your bootstrap/app.php file, load the configuration file:

    $app->configure('mail');
    

    I would put this line before you register your mail service provider, just to be safe.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测