flowmailer/flowmailer-php73-sdk

为 api.flowmailer.net REST API 提供的 Flowmailers PHP SDK

2.1.0 2024-06-13 07:29 UTC

README

为 api.flowmailer.net REST API 提供的 Flowmailers PHP 7.3 SDK

入门指南

安装

有关 HttpClient 发现的详细信息,请参阅 docs.php-http.org

正常安装可能如下所示

$ composer require symfony/http-client nyholm/psr7 flowmailer/flowmailer-php73-sdk

在 packagist 上选择您偏好的 客户端实现

有关如何在项目中使用多个实现时强制使用特定实现的信息,请参阅 github.com/php-http/discovery

基本用法

提交消息

<?php

require 'vendor/autoload.php';

use Flowmailer\API\Enum\MessageType;
use Flowmailer\API\Flowmailer;
use Flowmailer\API\Model\SubmitMessage;

// The credentials can be obtained in your Flowmailer account
$accountId    = '...';
$clientId     = '...';
$clientSecret = '...';

$flowmailer = Flowmailer::init($accountId, $clientId, $clientSecret);

$submitMessage = (new SubmitMessage())
    ->setMessageType(MessageType::EMAIL)
    ->setSubject('An e-mail message')
    ->setRecipientAddress('your-customer@email.org')
    ->setSenderAddress('info@your-company.com')
;

遍历先前提交的消息

<?php

use Flowmailer\API\Collection\MessageCollection;

$flowmailer           = Flowmailer::init($accountId, $clientId, $clientSecret);
$pageSize             = 100;
$savedReferenceOrNull = null; // Get reference from database or cache (null will start from the beginning of the list)
$referenceRange       = new ReferenceRange($pageSize, $savedReferenceOrNull);

while ($referenceRange instanceof ReferenceRange) {
    /** @var MessageCollection $result */
    $result = $flowmailer->getMessages($referenceRange);

    // Do stuff with the result here

    // Store $referenceRange->getReference() value here in database or cache as input for a future run
    // Now we set the ReferenceRange for the next loop in memory
    $referenceRange = $result->getNextRange();
}

高级用法

有关缓存、日志记录和一次性发送多条消息的示例,请参阅 高级用法
有关将消息排队以供稍后消费的信息,请参阅 排队消息