okamos/php-ses

PHP的Amazon SES API。支持签名版本4

8.0.1 2022-05-30 14:22 UTC

README

license
php-ses是一个用于Amazon Simple Email Service (SES) REST API的PHP库 Amazon SES

安装

通过Composer安装

composer require okamos/php-ses

入门

要开始,您需要引入ses.php

<php?
require_once('vendor/autoload.php');

此库需要您的AWS访问密钥ID和AWS密钥。

$ses = new SimpleEmailService(
    'AKI...', // your AWS access key id
    'your_secret...', // your AWS secret access key
    'us-west-2' // AWS region, default is us-east-1
);

// if you can't use verification of SSL certificate
$ses = new SimpleEmailService(
    'AKI...', // your AWS access key id
    'your_secret...', // your AWS secret access key
    'us-west-2' // AWS region, default is us-east-1
);

// method name's first character is must be lower case
$identities = $ses->listIdentities(); // string[]

版本指南

可用的API

  • ListIdentities
  • VerifyEmailIdentity
  • DeleteIdentity
  • SendEmail
  • GetSendQuota
  • GetSendStatistics
  • GetIdentityVerificationAttributes

用法

列出身份。

// List all identities your domains.
$identities = $ses->ListIdentities('Domain');
// List all identities your email addresses.
$identities = $ses->ListIdentities('EmailAddress');
$identities[0]; // your@email.com

验证电子邮件。

$ses->verifyEmailIdentity('your-email@example.com'); // return string(RequestId)

删除一个身份。

$ses->deleteIdentity('your-email@example.com'); // return string(RequestId)

获取验证令牌和状态。

$identities = [
    'your-email@example.com',
    'your-domain.com'
];
$entries = $ses->getIdentityVerificationAttributes($identities);
$entries[0]['Email']; // string (email)
$entries[0]['Token']; // string(token)
$entries[1]['Status']; // string(Pending | Success | Failed | TemporaryFailure)

获取您的AWS账户的发送配额。

$sendQuota = $ses->getSendQuota();
$sendQuota['Max24HourSend'] // string
$sendQuota['SentLast24Hours'] // string
$sendQuota['MaxSendRate'] // string

获取您的发送统计数据。

$data = $ses->getSendStatistics();
$data['Complaints'] // string
$data['Rejects'] // string
$data['Bounces'] // string
$data['DeliveryAttempts'] // string
$data['Timestamp'] // string

发送电子邮件基本用法。

$envelope = new SimpleEmailServiceEnvelope(
    'your-email@example.com',
    'Subject',
    'Message',
);
$envelope->addTo('to@example.com');

$requestId = $ses->sendEmail($envelope);

用HTML发送电子邮件。

$envelope = new SimpleEmailServiceEnvelope(
    'your-email@example.com',
    'Subject',
    'Message',
    '<p>Message</p><img src="http://example.com/any/image" alt="image"'
);
$envelope->addTo('to@example.com');

$requestId = $ses->sendEmail($envelope);

向多个目的地发送电子邮件。

$envelope = new SimpleEmailServiceEnvelope(
    'your-email@example.com',
    'Subject',
    'Message',
);
$envelope->addTo(['to1@example.com', 'to2@example.com']);
$envelope->addCc('cc1@example.com');
$envelope->addBcc(['bcc1@example.com'])

$requestId = $ses->sendEmail($envelope);

发送带有附件文件的电子邮件。

$envelope = new SimpleEmailServiceEnvelope(
    'your-email@example.com',
    'Subject',
    'Message',
);
$envelope->addTo('to@example.com');
$envelope->addAttachmentFromFile('filename.svg', '/Your/File/name.svg', 'image/svg');

$requestId = $ses->sendEmail($envelope);