流明5.3发送电子邮件 [英] Lumen 5.3 send email

查看:130
本文介绍了流明5.3发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用gmail smtp配置从Lumen发送电子邮件.我正在使用:

I tried send a email from Lumen using gmail smtp config. I am using:

  • illuminate/mail,版本5.3
  • lumen,版本5.3
  • illuminate/mail, Version 5.3
  • lumen, Version 5.3

我无法发送电子邮件.

我的路由器:

$app->get('/', function () use ($app) {
    $app->get('mail','mailcontroller@mail');
});

我的AppServiceProvider.php:

namespace App\Providers;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider {

    public function register() {
    $this->app->singleton('mailer', function ($app) {
        $app->configure('services');
        return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer');
        });
    }
}

我的.env配置:

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

我的邮件控制器:

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Mail;

class mailcontroller extends Controller {
    public function mail(){
        Mail::raw('Raw string email', function($msg) { 
            $msg->to(['****.com']); 
            $msg->from(['*****@gmail.com']); });
    }
}

我还启用了app.php中的以下行:

Also i have enable following lines in app.php:

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

推荐答案

聚会晚了一点,但这是我在Lumen 5.4中做的事情(我知道这可能有点笨拙,不适合所有人,但仍然):

A little late to the party, but here's how I've done it in Lumen 5.4 (and I know it might be a little clumsy and not suitable for everyone, but still):

1)插入illuminate/mail:

composer require illuminate/mail

2)将服务提供商添加到您的bootstrap/app.php:

2) add the service provider to your bootstrap/app.php:

$app->register(\Illuminate\Mail\MailServiceProvider::class);并取消注释$app->withFacades();

有可能/有可能​​通过.env可以实现以下目标,但我没有尝试过:

It's possible/likely the following can be achieved through .env but I haven't tried:

3)安装phanan的级联配置- https://github.com/phanan/cascading-config ,并按照此处介绍的Lumen的安装过程进行操作

3) Install phanan's cascading config - https://github.com/phanan/cascading-config and follow the installation process for Lumen described there

4)在应用程序的根目录中创建config文件夹,然后复制并粘贴完整的Laravel的config/mail.php

4) create config folder in your application's root and copy-paste full Laravel's config/mail.php

5)$app->configure('mail');添加到bootstrap/app.php

6)确保mail.php中的实际配置正确

6) make sure the actual config in mail.php is correct

现在,您应该可以像完整的Laravel安装一样发送邮件.

Now you should be able to send mails the same way you do in full Laravel installation.

这篇关于流明5.3发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆