亚马逊SES邮件散装

我正在尝试通过亚马逊SES设置电子邮件队列,以确保我可以同时发送多封电子邮件(每秒限制为14封电子邮件)。

我不断收到错误信号

该电子邮件未发送。 错误消息:在“https://email.us-west-2.amazonaws.com”上执行“SendEmail”时出错。 AWS HTTP错误:客户端错误: POST https://email.us-west-2.amazonaws.com导致403 Forbidden响应:发件人SignatureDo(截断...)SignatureDoesNotMatch(客户端):我们计算的请求签名没有匹配您提供的签名。 检查您的AWS秘密访问密钥和签名方法。 详细信息请参阅服务文档。 该请求的规范字符串应该是'POST / aws-sdk-invocation-id:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0 host:email.us-west-2.amazonaws.com x-amz-date:20170311T031541Z aws-sdk-invocation-id; aws-sdk-retry; host; x-amz-date 486b4c1288d7c5717c3a0bccdaf10f67eb02ca5da8fbfed75298e98e8f785048'String-to-Sign应该是'AWS4-HMAC-SHA256 20170311T031541Z 20170311 / us-west-2 / email / aws4_request ce02f756d98ab45ab63754fd6ec64a6621c36ed802316ff22c2c877535925735' - 发件人SignatureDoesNotMatch我们计算的请求签名与您提供的签名不匹配。 检查您的AWS秘密访问密钥和签名方法。 详细信息请参阅服务文档。 该请求的规范字符串应该是'POST / aws-sdk-invocation-id:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0 host:email.us-west-2.amazonaws.com x-amz-date:20170311T031541Z aws-sdk-invocation-id; aws-sdk-retry; host; x-amz-date 486b4c1288d7c5717c3a0bccdaf10f67eb02ca5da8fbfed75298e98e8f785048'String-to-Sign应该是'AWS4-HMAC-SHA256 20170311T031541Z 20170311 / us-west-2 / email / aws4_request ce02f756d98ab45ab63754fd6ec64a6621c36ed802316ff22c2c877535925735'028b5fb9-0609-11e7-9549-6d5ec2e3cc18

我尝试了其他的解决方案,但没有成功。

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发送库

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发送multiple emails via AWS SES使用此库AWS SES BULK EMAIL SENDING

<?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];
}
链接地址: http://www.djcxy.com/p/39001.html

上一篇: Amazon SES Emails in Bulk

下一篇: Signature does not match in Amazon Web Services