silinternational/email-service-php-client

PHP 客户端,用于与我们的 Email Service API 交互:https://github.com/silinternational/email-service

2.4.2 2024-02-28 19:11 UTC

This package is auto-updated.

Last update: 2024-08-31 04:24:31 UTC


README

PHP 客户端,用于与我们的 Email Service API 交互。

此客户端基于 Guzzle PHP HTTP 客户端构建。Guzzle 提供了一种简单的方法来创建 API 客户端,通过使用类似于 Swagger 的格式描述 API,无需自己实现每个方法。因此,支持更多 API 相对简单。

安装

使用 Composer 安装很简单。

$ composer require silinternational/email-service-php-client

用法

示例

<?php

use Sil\EmailService\Client\EmailServiceClient;

$emailServiceClient = new EmailServiceClient(
    'https://api.example.com/', // The base URI for the API.
    'DummyAccessToken', // Your HTTP header authorization bearer token.
    [
        'http_client_options' => [
            'timeout' => 10, // An (optional) custom HTTP timeout, in seconds.
        ],
    ]
);

$email = $emailServiceClient->email([
    "to_address" => "test@domain.com",
    "cc_address" => "other@domain.com",   // optional
    "bcc_address" => "bcc@domain.com",    // optional
    "subject" => "Test Subject",
    "text_body" => "this is text",        // either text_body or html_body is required, but both can be provided
    "html_body" => "<b>this is html</b>",
]);

要发送延迟一定时间的邮件:`

$email = $emailServiceClient->email([
    "to_address" => "test@domain.com",
    "subject" => "Test Subject",
    "html_body" => "<b>this is html</b>",
    "delay_seconds" => "3600",
]);

或者要安排发送邮件,请使用 send_after 和 Unix 时间戳

$email = $emailServiceClient->email([
    "to_address" => "test@domain.com",
    "subject" => "Test Subject",
    "html_body" => "<b>this is html</b>",
    "send_after" => "1556825944",
]);

测试

要运行此单元测试,请运行 make test

Guzzle 服务客户端说明