viitech / laravel-mailjet
Laravel 邮件jet API V3 和 Laravel Mailjet 邮件传输工具包
Requires
- php: >=7.1.3
- laravel/framework: >=5
- laravel/tinker: ~1.0
- mailjet/mailjet-apiv3-php: ^1.2
- mailjet/mailjet-swiftmailer: ^2.0
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: 0.9.*
- orchestra/testbench: 3.6
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2024-09-19 17:59:36 UTC
README
使用此包装器处理 Mailjet API v3 的 Laravel 包:https://github.com/mailjet/mailjet-apiv3-php
它还提供了用于 Laravel 邮件功能 的 mailjetTransport
安装
首先,将包包含在依赖关系中
composer require mailjet/laravel-mailjet
然后,您需要在配置文件中添加一些信息。您可以在 此处 找到您的 Mailjet API 密钥/密码
- 在 providers 数组中
'providers' => [ ... Mailjet\LaravelMailjet\MailjetServiceProvider::class, Mailjet\LaravelMailjet\MailjetMailServiceProvider::class, ... ]
- 在 aliases 数组中
'aliases' => [ ... 'Mailjet' => Mailjet\LaravelMailjet\Facades\Mailjet::class, ... ]
- 在 services.php 文件中
mailjet' => [ 'key' => env('MAILJET_APIKEY'), 'secret' => env('MAILJET_APISECRET'), ]
- 在您的 .env 文件中
MAILJET_APIKEY=YOUR_APIKEY MAILJET_APISECRET=YOUR_APISECRET
完整配置
'mailjet' => [ 'key' => env('MAILJET_APIKEY'), 'secret' => env('MAILJET_APISECRET'), 'transactional' => [ 'call' => true, 'options' => [ 'url' => 'api.mailjet.com', 'version' => 'v3.1', 'call' => true, 'secured' => true ] ], 'common' => [ 'call' => true, 'options' => [ 'url' => 'api.mailjet.com', 'version' => 'v3', 'call' => true, 'secured' => true ] ] ]
您可以将设置传递给 MailjetClient。
transactional
:发送 API 客户端设置common
:通过 Facade Mailjet 访问 MailjetClient 的设置
邮件驱动配置
为了将 Mailjet 用作您的邮件驱动程序,您需要更新您的 config/mail.php
或您的 .env
文件中的邮件驱动程序,设置为 MAIL_DRIVER=mailjet
,并确保您正在使用一个有效的、经过授权的邮箱地址,该邮箱地址配置在您的 Mailjet 账户上。发送的电子邮件地址和域可以在 此处 管理
有关用法,请参阅 Laravel 邮件文档
用法
为了使用此包,您首先需要在您的代码中导入 Mailjet Facade
use Mailjet\LaravelMailjet\Facades\Mailjet;
然后,在您的代码中,您可以使用 MailjetServices 中可用的一种方法
低级 API 方法
Mailjet::get($resource, $args, $options)
Mailjet::post($resource, $args, $options)
Mailjet::put($resource, $args, $options)
Mailjet::delete($resource, $args, $options)
高级 API 方法
Mailjet::getAllLists($filters)
Mailjet::createList($body)
Mailjet::getListRecipients($filters)
Mailjet::getSingleContact($id)
Mailjet::createContact($body)
Mailjet::createListRecipient($body)
Mailjet::editListrecipient($id, $body)
有关您可以在每个方法中使用的过滤器信息,请参阅 Mailjet API 文档
所有方法返回 Mailjet\Response
或在 API 错误的情况下抛出 MailjetException
您还可以使用 getClient()
方法获取 Mailjet API 客户端,并对 Mailjet API 进行自定义请求。
待办事项
- 添加更多单元测试以增加代码覆盖率。