dyanakiev / laravel-sparkpost-driver
SparkPost 驱动程序,适用于 Laravel 6.x|7.x|8.x
Requires
- php: ^8.0.2
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- laravel/framework: ^8.0|^9.0|^10.0
- symfony/mailer: ^6.0
README
描述
此包允许您继续在 Laravel 中使用 SparkPost 作为邮件驱动程序。
此包受以下启发:[https://github.com/clarification/sparkpost-laravel-driver](https://github.com/clarification/sparkpost-laravel-driver),并更新了来自 Laravel 5.8.x 的驱动程序。
版本
在下面的表格中找到正确版本的用法
安装
您可以通过 composer 安装此包。
composer require vemcogroup/laravel-sparkpost-driver
包将自动注册其服务提供程序。
使用
SparkPost API 选项
您可以为以下选项定义特定的 [SparkPost 选项]([https://developers.sparkpost.com/api/transmissions/#header-request-body](https://developers.sparkpost.com/api/transmissions/#header-request-body))如 open_tracking
、click_tracking
、transactional
。
欧盟 GDPR
您可以通过设置 endpoint
选项使用欧盟端点以符合欧洲 GDPR 规范,或者默认将使用。
SparkPost(默认):https://api.sparkpost.com/api/v1
SparkPost EU:https://api.eu.sparkpost.com/api/v1
Guzzle 选项
您可以在 SparkPost 配置部分 guzzle
中指定 Guzzle 选项。
只需将 sparkpost 服务添加到您的 config/services.php
。
'sparkpost' => [ 'secret' => env('SPARKPOST_SECRET'), // optional guzzle specific configuration 'guzzle' => [ 'verify' => true, 'decode_content' => true, ... ], 'options' => [ // configure endpoint, if not default 'endpoint' => env('SPARKPOST_ENDPOINT'), // optional Sparkpost API options go here 'return_path' => 'mail@bounces.domain.com', 'options' => [ 'open_tracking' => false, 'click_tracking' => false, 'transactional' => true, ], ], ],
API 密钥
您还需要将 SparkPost API 密钥添加到您的环境文件中。
SPARKPOST_SECRET=__Your_key_here__
最后,您需要将邮件驱动程序设置为 SparkPost。您可以通过更改 config/mail.php
中的驱动程序来完成此操作。
'driver' => env('MAIL_DRIVER', 'sparkpost'),
或在您的 .env
文件中设置环境变量 MAIL_DRIVER
。
MAIL_DRIVER=sparkpost
Laravel 7
如果您正在使用干净的 Laravel 7.x 安装,那么在 config/mail.php
的 mailer 部分添加以下 SparkPost 配置很重要。
'mailers' => [ ... 'sparkpost' => [ 'transport' => 'sparkpost' ], ... ],
并将 .env 中的 MAIL_DRIVER
替换为 MAIL_MAILER
,确保在 config/services.php
中保留 SparkPost 配置。
辅助函数
删除抑制
sparkpost_delete_supression('test@example.com');
验证单个电子邮件地址
sparkpost_check_email('test@example.com');