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
发布配置文件
$ php artisan vendor:publish --provider="qoraiche\mailEclipse\mailEclipseServiceProvider"
$ php artisan migrate
手动创建 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 。
点击按钮,新建一个 Mail 类
添加模板
扩展包提供了丰富的模板,可以直接使用。
选择一个模板,可以稍微修改一下。
修改刚才创建的 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');
}
查看发送的邮件。
使用 Markdown
代码版本控制
这个扩展包还处于开发阶段,如果你有兴趣可以给作者提建议或者 PR,让这个扩展包更加的好用。
$ git add -A
$ git commit -m 'qoraiche/laravel-mail-editor'