使用 Amazon SES API 和 Amazon SDK for PHP 版本 3 来监控发送活动 - Amazon SDK for PHP
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon SES API 和 Amazon SDK for PHP 版本 3 来监控发送活动

Amazon Simple Email Service (Amazon SES) 提供了监控发送活动的方法。我们建议您实现这些方法,以便您可以跟踪重要的指标,如您账户的邮件退回率、投诉率和拒绝率。过高的退回邮件率和投诉率可能会影响您使用 Amazon SES 发送电子邮件的能力。

以下示例演示如何:

的所有示例代码都可以在此Amazon SDK for PHP处找到 GitHub

凭证

运行示例代码之前,请配置您的 Amazon 凭证,如 凭证 中所述。然后导入 Amazon SDK for PHP,如 基本用法 中所述。

有关使用 Amazon SES 的更多信息,请参阅 Amazon SES 开发人员指南

检查发送配额

在单个 24 小时期间,您只能发送特定数量的邮件。要查看仍允许您发送多少消息,请使用GetSendQuota操作。有关更多信息,请参阅 管理 Amazon SES 发送限制

导入

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Ses\SesClient;

示例代码

$SesClient = new SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-1' ]); try { $result = $SesClient->getSendQuota(); $send_limit = $result["Max24HourSend"]; $sent = $result["SentLast24Hours"]; $available = $send_limit - $sent; print("<p>You can send " . $available . " more messages in the next 24 hours.</p>"); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

监控发送活动

要检索您在过去两周内发送的消息的指标,请使用GetSendStatistics操作。此示例以 15 分钟为增量,返回传送尝试的次数、退回邮件数、投诉邮件数和拒绝邮件数。

导入

require 'vendor/autoload.php'; use Aws\Exception\AwsException; use Aws\Ses\SesClient;

示例代码

$SesClient = new SesClient([ 'profile' => 'default', 'version' => '2010-12-01', 'region' => 'us-east-1' ]); try { $result = $SesClient->getSendStatistics(); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }