使用 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 区域中的所有发件人和收件人均必须经过验证。有关发送电子邮件的更多信息,请参阅使用 Amazon SES 发送电子邮件

以下示例演示如何:

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

凭证

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

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

验证电子邮件地址

Amazon SES 只能从已验证的电子邮件地址或域发送电子邮件。通过验证电子邮件地址,您可证明您是该地址的所有者,并希望允许 Amazon SES 从该地址发送电子邮件。

运行以下代码示例时,Amazon SES 将向您指定的地址发送一封电子邮件。当您(或电子邮件的收件人)单击电子邮件中的链接时,该地址将得到验证。

要将电子邮件地址添加到您的 Amazon SES 账户,请使用VerifyEmailIdentity操作。

导入

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

示例代码

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

验证电子邮件域

Amazon SES 只能从已验证的电子邮件地址或域发送电子邮件。通过验证域,您可证明自己是该域的所有者。在验证域时,允许 Amazon SES 从该域上的任何地址发送电子邮件。

当运行以下代码示例时,Amazon SES 向您提供验证令牌。您必须将令牌添加到域的 DNS 配置。有关更多信息,请参阅 Amazon Simple Email Service 开发人员指南中的使用 Amazon SES 来验证域

要将发送域名添加到您的 Amazon SES 账户,请使用VerifyDomainIdentity操作。

导入

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

示例代码

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

列出电子邮件地址

要检索在当前Amazon地区提交的电子邮件地址列表,无论验证状态如何,请使用ListIdentities操作。

导入

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

示例代码

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

列出电子邮件域

要检索在当前Amazon地区提交的电子邮件域名列表,无论验证状态如何,均可使用该ListIdentities操作。

导入

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

示例代码

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

删除电子邮件地址

要从身份列表中删除经过验证的电子邮件地址,请使用DeleteIdentity操作。

导入

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

示例代码

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

删除电子邮件域

要从已验证身份列表中删除经过验证的电子邮件域,请使用DeleteIdentity操作。

导入

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

示例代码

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