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 网站上。

上一篇 下一篇
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
发起讨论 只看当前版本


暂无话题~