087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

发送邮件是一个非常常用的功能,例如用户注册成功后的邮箱验证,忘记密码往邮箱发送密码重置链接等等。今天要介绍的这个扩展包 qoraiche/laravel-mail-editor 提供了图形界面来创建和管理项目中要发送的邮件,大大提高了我们的开发效率。

安装

$ git checkout -b email-editor
$ composer require qoraiche/laravel-mail-editor

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

发布配置文件

$ php artisan vendor:publish --provider="qoraiche\mailEclipse\mailEclipseServiceProvider"
$ php artisan migrate

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

手动创建 Mailable

不使用扩展包的情况下,需要通过命令行创建邮件类,例如

$ php artisan make:mail Test
$ mkdir resources/views/mails
$ touch resources/views/mails/test.blade.php

app/Mail/Test.php

    public function build()
    {
        return $this->view('mails.test');
    }

resources/views/emails/test.blade.php

test email

使用 MailEclipse

扩展包提供了 Web 界面用来管理邮件类,访问 package.test/maileclipse

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

点击按钮,新建一个 Mail 类

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

添加模板

扩展包提供了丰富的模板,可以直接使用。

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

选择一个模板,可以稍微修改一下。
087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

修改刚才创建的 Welcome 类。

app/Mail/Welcome.php

    public function build()
    {
        return $this->view('maileclipse::templates.welcome');
    }

使用刚才创建的模板。

使用 Mailhog

如果你使用的是 Homestead 那么可以使用 Mailhog 测试邮件,如果使用的是 Laradock 则可以启动 mailhog。

$ docker-compose up -d mailhog

修改一下 env 配置。

.env

MAIL_DRIVER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

测试发送一个邮件,打开 tinker。

app/Mail/Welcome.php

    public function build()
    {
        return $this->view('maileclipse::templates.welcome');
    }

查看发送的邮件。

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

使用 Markdown

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

087. Laravel Email 编辑器 —— qoraiche/laravel-mail-editor

代码版本控制

这个扩展包还处于开发阶段,如果你有兴趣可以给作者提建议或者 PR,让这个扩展包更加的好用。

$ git add -A
$ git commit -m 'qoraiche/laravel-mail-editor'

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
发起讨论 只看当前版本


暂无话题~