ismailshurrab / mailman
使用 CSS 内联简化 Laravel 5 的邮件发送。
3.0
2021-01-07 10:59 UTC
Requires
- illuminate/mail: ^5.0|^6.0|^7.0|^8.0
- illuminate/queue: ^5.0|^6.0|^7.0|^8.0
- illuminate/support: ^5.0|^6.0|^7.0|^8.0
- illuminate/view: ^5.0|^6.0|^7.0|^8.0
- tijsverkoyen/css-to-inline-styles: 2.*
Requires (Dev)
- mockery/mockery: 0.9.*
- orchestra/testbench: ^3.1
- phpunit/phpunit: 4.7.*
README
简介
Mailman 包含了 Laravel 的所有邮件功能,并且允许你
- Keep your email css files in an external file, and automatically inline them when sending an email.
- Set the language in which the email should be sent, without affecting the rest of your application.
- Avoid the annoying use of callbacks.
WAAVI 是一家位于西班牙马德里的网络开发工作室。你可以在 waavi.com 了解更多关于我们的信息
Laravel 兼容性
安装
通过 composer 安装
composer require waavi/mailman 2.0.x
或者手动编辑你的 composer.json 文件
"require": {
"waavi/mailman": "2.0.x"
}
发布配置文件
php artisan vendor:publish
在 config/app.php 中,将以下条目添加到 providers 数组的末尾
\Waavi\Mailman\MailmanServiceProvider::class,
并且编辑 aliases 数组以包含
'Mailman' => \Waavi\Mailman\Facades\Mailman::class,
使用方法
基本示例
使用方法与 Laravel 的 Mail 非常相似,无需回调。实际上,Mailman 预期将像使用视图一样使用。假设你有一个在 views/emails/email 的电子邮件视图。你可以通过以下方式发送电子邮件
Mailman::make('emails.email')->to('info@example.com')->subject('test')->send();
来自地址和一般电子邮件配置将从 app/mail.php 加载,而电子邮件样式表配置是通过 mailman.php 配置文件完成的。
向电子邮件视图传递数据
如果你想向视图传递数据,你可以通过 make 方法或 with 方法完成,就像在视图中的那样
Mailman::make('emails.welcome', array('user' => $user))->to('user@example.com')->subject('welcome')->send();
Mailman::make('emails.welcome')->with(['user', $user])->to('user@example.com')->subject('welcome')->send();
Mailman::make('emails.welcome')->with('user', $user)->to('user@example.com')->subject('welcome')->send();
设置区域设置
要设置发送电子邮件的区域设置,你可以使用 set locale 方法
Mailman::make('emails.basic')->setLocale('es')->to('user@example.com')->subject('hello')->send();
设置要使用的 CSS 文件
你可以设置与默认不同的 CSS 文件。参数必须是相对于基础文件夹的完整路径
Mailman::make('emails.basic')->setCss('resources/assets/css/private.css')
排队发送电子邮件
你可以像使用 Laravel 的 Mail 一样排队发送电子邮件。要通过队列发送电子邮件
Mailman::make('emails.basic')->to...->queue() // Queue in default queue.
Mailman::make('emails.basic')->to...->queue('queue_name') // Queue in queue_name queue.
Mailman::make('emails.basic')->to...->later(5) // Send email after 5 seconds.
Mailman::make('emails.basic')->to...->laterOn(5, 'queue_name')
模拟发送电子邮件
如果你使用 Laravel 的 Homestead,建议安装 MailCatcher。
获取电子邮件字符串
对于调试,能够打印电子邮件的内容通常很有用。使用 Mailman,你可以使用 Mailman::show() 获取电子邮件正文
Mailman::make('emails.basic')->to('user@example.com')->subject('hello')->show();
常见方法(Illuminate\Mail\Message)
Illuminate\Mail\Message 中的所有方法都可通过 Mailman 使用
Mailman::make('emails.basic')->to('john@doe.it')
Mailman::make('emails.basic')->to('john@doe.it', 'John Doe') // Set the recipient.
Mailman::make('emails.basic')->from('john@doe.it')
Mailman::make('emails.basic')->from('john@doe.it', 'John Doe') // Set from field.
Mailman::make('emails.basic')->sender('john@doe.it')
Mailman::make('emails.basic')->sender('john@doe.it', 'John Doe') // Set sender.
Mailman::make('emails.basic')->returnPath('john@doe.it') // Set return path.
Mailman::make('emails.basic')->cc('john@doe.it')
Mailman::make('emails.basic')->cc('john@doe.it', 'John Doe') // Add carbon copy.
Mailman::make('emails.basic')->bcc('john@doe.it')
Mailman::make('emails.basic')->bcc('john@doe.it', 'John Doe') // Add blind carbon copy.
Mailman::make('emails.basic')->replyTo('john@doe.it')
Mailman::make('emails.basic')->replyTo('john@doe.it', 'John Doe') // Add reply to.
Mailman::make('emails.basic')->subject('Subject text') // Add subject
Mailman::make('emails.basic')->priority(5) // Set priority level
Mailman::make('emails.basic')->attach('file/test.pdf', $options) // Attach file
Mailman::make('emails.basic')->attachData($data, $name, $options) // Attach in-memory data
Mailman::make('emails.basic')->embed('file/test.jpg') // Embed file and get cid
Mailman::make('emails.basic')->embedData($data, $name, $contentType) // Embed data