我正在尝试通过Amazon SES设置电子邮件队列,以确保我可以在Sametime上发送多个电子邮件(每秒14封电子邮件)。
我经常得到一个错误
没有发送电子邮件。错误消息:在" https://email.us-west-2.amazonaws.com上执行" sendemail"的错误";AWS HTTP错误:客户端错误:
POST https://email.us-west-2.amazonaws.com
导致403 Forbidden
响应:Sender signaturedo(截断...)signaturedoesnotmatch(client):我们计算出的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法。有关详细信息,请咨询服务文档。此请求的规范字符串应该是'post/aws-sdk-invocation-id:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0主持人:email.us.us-west-west-west-west-2.amazonaws.com x-amz-date:2017031311311311311311311311311311311311311311311311541SZCE02F756D98AB45AB63754FD64A66621C36ED802316FF22C2C2C87777535925735'-发送器signer signaturedoesnotmmath,我们计算的我们所计算的请求签名与您提供的签名不匹配您提供的签名。检查您的AWS秘密访问密钥和签名方法。有关详细信息,请咨询服务文档。此请求的规范字符串应该是'post/aws-sdk-invocation-id:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0主持人:email.us.us-west-west-west-west-2.amazonaws.com x-amz-date:2017031311311311311311311311311311311311311311311311541SZ
我在stackoverflow上尝试了其他解决方案,但没有成功。
PHP代码:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// aws.amazon.com/code/
// docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html
// Replace path_to_sdk_inclusion with the path to the SDK as described in
// docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html
define('REQUIRED_FILE','aws/aws-autoloader.php');
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'no-reply@mydomain.com');
// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'admin@mydomain.com');
// Replace us-west-2 with the AWS region you're using for Amazon SES.
define('REGION','us-west-2');
define('SUBJECT','Amazon SES test (AWS SDK for PHP)');
define('BODY','This email was sent with Amazon SES using the AWS SDK for PHP.');
require REQUIRED_FILE;
use AwsSesSesClient;
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => REGION,
'credentials' => array(
'key' => 'xxxx',
'secret' => 'xxxx',
)
));
$request = array();
$request['Source'] = SENDER;
$request['Destination']['ToAddresses'] = array(RECIPIENT);
$request['Message']['Subject']['Data'] = SUBJECT;
$request['Message']['Body']['Text']['Data'] = BODY;
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
echo("Email sent! Message ID: $messageId"."n");
} catch (Exception $e) {
echo("The email was not sent. Error message: ");
echo($e->getMessage()."n");
}
如果您可以帮助您,您将度过我的一天。
aws ses bulk sending库
AWS SDK V3文档
安装
步骤1。 Create Composer.json
{
"require": {
"aws/aws-sdk-php": "3.*"
}
}
步骤2。 composer install
AWS SDK V2文档
安装
此代码将用于使用SES AWS SDK版本3的一对一发送。希望这能起作用。用于发送multiple emails via AWS SES
使用此库AWS SES批量电子邮件发送
<?php
$sesClient = AwsSesSesClient::factory(array(
'credentials' => array(
'key' => $accessKey,
'secret' => $secretKey,
),
"region" => "us-east-1",
"version" => "2010-12-01"
));
$mail = new PHPMailer_PHPMailer();
$mail->CharSet = "UTF-8";
$mail->AddAddress($receiverEmail);
$mail->setFrom($senderEmail, $senderName);
$mail->Subject = $subject;
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
try
{
$response = $sesClient->sendRawEmail(array("RawMessage" => array("Data" => $mime)));
$MessageId = $response->get("MessageId");
$metaData = $response->get("@metadata");
if (!empty($MessageId))
{
$sent[]=$MessageId;
$sent[]=$metaData["headers"]['x-amzn-requestid'];
}
} catch (Exception $ex)
{
echo $response = $ex->getMessage();
$xmlResponse = explode('<Code>', $response);
$parsedResponse = explode('</Code>', $xmlResponse[2]);
$failed[]=$parsedResponse[0];
}