本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Amazon SES API 和Amazon SDK for PHP版本 3
当您首次开始使用 Amazon Simple Email Service (Amazon SES) 账户时,您将发送人和收件人均必须经过同一个账户中的验证Amazon您要向其发送电子邮件的地区。有关发送电子邮件的更多信息,请参阅使用 Amazon SES 发送电子邮件。
以下示例演示如何:
GHEREAmazon SDK for PHP可用此处 GitHub
凭证
运行示例代码之前,请配置您的Amazon凭证,如中所述设置凭证. 然后导入Amazon SDK for PHP,如所述基本用法.
有关使用 Amazon SES 的更多信息,请参阅Amazon SES 开发人员.
验证电子邮件地址
Amazon SES 只能从已验证的电子邮件地址或域发送电子邮件。通过验证电子邮件地址,您可证明您是该地址的所有者,并希望允许 Amazon SES 从该地址发送电子邮件。
运行以下代码示例时,Amazon SES 将向您指定的地址发送一封电子邮件。当您(或电子邮件的收件人)单击电子邮件中的链接时,该地址将得到验证。
要添加电子邮件地址到您的 Amazon SES 账户,请使用VerifyEmailIdentityoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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 SES 验证域(在《Amazon Simple Emailice 开发人员指南
要添加发送域到您的 Amazon SES 账户,请使用VerifyDomainIdentityoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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区域,无论验证状态如何,都使用ListIdentitiesoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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区域,无论验证状态如何,都使用ListIdentitiesoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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"; }
删除电子邮件地址
要从身份列表中删除某个经过验证的电子邮件地址,请使用DeleteIdentityoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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"; }
删除电子邮件域
要从经过验证的身份列表中删除某个经过验证的电子邮件地址,请使用DeleteIdentityoperation.
导入
require 'vendor/autoload.php'; use Aws\Ses\SesClient; 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"; }