avido / smtpeter-php-api
smtpeter.com 的 API 客户端
0.0.7
2022-11-22 12:57 UTC
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- illuminate/collections: ^8.0|^9.0
Requires (Dev)
- overtrue/phplint: ^2.3
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-09-22 17:13:56 UTC
README
此版本尚未准备好用于生产环境,请自行承担风险使用!
要求
要使用 smtpeter API 客户端,需要以下条件
- Copernica 账户
- 生成您的API 密钥
安装
您可以使用 composer 安装此包。
composer require avido/smtpeter-php-api
入门
初始化 Smtpeter php api 客户端并设置您的 API 密钥
$client = new \Avido\Smtpeter\Client($apiKey);
模板
列出所有模板
可以使用 offset
和 limit
变量限制模板列表的结果
$templates = $client->templates->list(); $templatesWithLimit = $client->templates->list($offset, $limit);
检索特定模板
$template = $client->template->get($id);
电子邮件
使用模板发送电子邮件
// simple email $email = new Email([ 'templateId' => 1, 'to' => 'receiver@domain.tld', 'data' => ['array' => 'of replacement vars'] ]); // email with bcc $email = new Email([ 'templateId' => 1, 'to' => 'receiver@domain.tld', 'bcc' => 'bcc@domain.tld', 'data' => ['array' => 'of replacement vars'] ]); // email with replyTo address $email = new Email([ 'templateId' => 1, 'to' => 'receiver@domain.tld', 'replyTo' => 'replyTo@domain.tld', 'data' => ['array' => 'of replacement vars'] ]); $client->email->send($email);
重发电子邮件
$messageId = 'abcdef1234'; $client->email->resend($messageId );
检索电子邮件
$messageId = 'abcdef1234'; // by default only the html body is retrieved. $loadHtml = true; $loadAttachments = true; $loadHeaders = true; $client->email->get($messageId, $loadHtml, $loadAttachments, $loadHeaders);
事件
获取特定 messageId 的事件
$messageId = 'abcdef1234'; $events = $client->events->message($messageId); // optional you can filter by date/ tags $from = '2022-01-01'; $end = '2022-01-07'; $filterd = $client->events->message($messageId, $from, $end); print_r($events); ... Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => Avido\Smtpeter\Resources\Event Object ( [id] => abcdef1234 [time] => DateTime Object ( [date] => 2022-02-01 08:36:01.000000 [timezone_type] => 3 [timezone] => UTC ) [recipient] => recipient@domain.tld ... ) ) )
更多示例请参阅 tests
文件夹