gsferro / servicemail
该软件包最新版本(v1.1.1)没有可用的许可证信息。
Laravel 中通过队列发送邮件的简单服务
v1.1.1
2021-05-04 18:30 UTC
Requires
- predis/predis: 1.*
This package is auto-updated.
Last update: 2024-09-05 01:59:40 UTC
README
Laravel 中通过队列发送邮件的简单服务
通过 composer 安装
composer require gsferro/servicemail
配置
- 将 ServiceProvider 添加到
app.php
的 providers 中
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/
\Gsferro\ServiceMail\Providers\ServiceMailServiceProvider::class,
- 在
EventServiceProvider.php
中添加到$listen
的事件
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/
'Gsferro\ServiceMail\Events\MailerEvent' => [
'Gsferro\ServiceMail\Listeners\MailerJobListener',
],
- 发布配置
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider" --tag=config
使用方法
<?php servicemail()->send( string $view, string $subject, string $to, $data, ?\DateTime $timeEvent = null, string $attach = null, $cc = null );
- 生成迁移
- php artisan queue:table
- php artisan queue:failed-table
替代 mailtrap
- 在 .env 或 config/servicemail.php 中设置变量
SERVICEMAIL_REDIRECT
以将邮件发送给自己作为调试/测试
使用 sqlite 数据库
- 创建本地数据库
touch database/database.sqlite
- 发布 migrations 在 migrations/servicemail
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider" --tag=migrations
- 修改文件
config/database.php
'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => database_path( 'database.sqlite' ), 'prefix' => '', 'foreign_key_constraints' => env( 'DB_FOREIGN_KEYS', true ), ],
- 修改文件
config/queue.php
'connections' => [ 'sqlite' => [ 'connection' => 'sqlite', 'driver' => 'database', 'table' => 'jobs', 'queue' => 'default', 'retry_after' => 90, ],
- 修改文件
.env
QUEUE_CONNECTION="sqlite"
或者在 config/queue.php
中直接设置
[ 'default' => "sqlite", ]
运行迁移
php artisan migrate --database=sqlite --path=database/migrations/jobs
运行队列
php artisan queue:work sqlite --tries=3