pendable / laravel-mailer
Laravel 包,用于通过 Pendable API 发送邮件
v1.0.2
2023-09-10 13:03 UTC
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- illuminate/mail: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- pendable/symfony-mailer: ^1.0
Requires (Dev)
- ext-gd: *
- fakerphp/faker: ^1.17
- orchestra/testbench: ^7.19|^8.0
- phpunit/phpunit: ^9.0
README
为 Laravel 提供 Pendable 集成。此包在底层使用 pendable-symfony 邮件发送器。
Pendable
Pendable 提供了一个围绕 Amazon SES 的包装服务,添加了以下功能:并行化邮件发送、优先级排序邮件、将来安排邮件发送、跟踪打开、点击和其他事件、基于退订和投诉的主动限流、过滤垃圾邮件域名、维护健康联系人列表、检索、调试和重新发送消息、所有客户沟通的时间线视图。
更多信息请访问 pendable.io
安装
在项目目录中打开命令行控制台,并执行以下命令以下载此捆绑包的最新稳定版本
$ composer require pendable/laravel-mailer
然后将您的 pendable API 密钥添加到 .env 文件中
# Pendable API Key from https://pendable.io PENDABLE_API_KEY=your-api-key # Use the pendable mailer MAIL_MAILER=pendable
用法
Pendable 邮件发送器提供了 Laravel 邮件发送器的直接替换。要发送消息,只需像平时一样使用 Mail
门面即可。
Mail::to('my-email@example.com')->send(new MyMailable);
高级用法
在运行时设置选项
// Laravel mailable instance $mailable = new MyMailable; // adding tags $mailable->tag('my-tag-1'); $mailable->tag('my-tag-2'); // adding custom fields $mailable->metadata('custom_1', 'one'); $mailable->metadata('custom_2', 'two'); $mailable->withSymfonyMessage(function(Email $message){ // set the priority $message->getHeaders()->addTextHeader('priority', 60); // set the config identifier $message->getHeaders()->addTextHeader('config_identifier', 'my-config'); // set the client email id (usually your system's unique identifier) $message->getHeaders()->addTextHeader('client_email_id', '1'); // set the schedule send at (in ISO 8601 format) $message->getHeaders()->addTextHeader('schedule_send_at', '2023-06-25T22:37:26+05:30'); }); // send the mail Mail::to('my-email@example.com')->send($mailable);
在可邮寄类本身设置选项
use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Headers; use Illuminate\Queue\SerializesModels; use Illuminate\Mail\Mailables\Envelope; class MyMailable extends Mailable { use Queueable, SerializesModels; public function headers(): Headers { return new Headers( text: [ // set the priority 'priority' => '60', // set the config identifier 'config_identifier' => 'my-config', // set the client email id (usually your system's unique identifier) 'client_email_id' => '1', // set the schedule send at (in ISO 8601 format) 'schedule_send_at' => '2023-06-25T22:37:26+05:30', ], ); } /** * Get the message envelope. */ public function envelope(): Envelope { return new Envelope( subject: 'My Mailer from Laravel + Pendable', // Setting tags tags: ['test', 'mailer', 'laravel'], // Setting custom fields metadata: [ 'custom_1' => 'one', 'custom_2' => 'two', ], ); } // ... } # To send the mail Mail::to('my-email@example.com')->send(new MyMailable);