AWS ses sendEmail php sdk错误电子邮件地址未验证

问题描述 投票:0回答:1

我正在尝试使用php sdk通过AWS SES发送电子邮件。请注意,我能够通过aws CLI发送消息-没问题,并且能够使用Identity Management区域下的域和电子邮件区域从SES控制台发送电子邮件。此外,域和电子邮件均已通过验证,并显示在“身份管理”区域中。

我正在使用PHP SDK中的示例代码。我确实编辑了该区域,因为我的电子邮件和域已经过验证,并且我在us-west-2区域之外进行操作。

<?php
/**
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * This file is licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. A copy of
 * the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
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-west-2'
]);

$html_body = '<h1>AWS Amazon Simple Email Service Test Email</h1>' .
    '<p>This email was sent with <a href="https://aws.amazon.com/ses/">' .
    'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">' .
    'AWS SDK for PHP</a>.</p>';
$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was send with Amazon SES using the AWS SDK for PHP.';
$sender_email = 'email_address';
$recipient_emails = ['email_address'];
$char_set = 'UTF-8';
$configuration_set = 'ConfigSet';

try {
    $result = $SesClient->sendEmail([
        'Destination' => [
            'ToAddresses' => $recipient_emails,
        ],
        'ReplyToAddresses' => [$sender_email],
        'Source' => $sender_email,
        'Message' => [

            'Body' => [
                'Html' => [
                    'Charset' => $char_set,
                    'Data' => $html_body,
                ],
                'Text' => [
                    'Charset' => $char_set,
                    'Data' => $plaintext_body,
                ],
            ],
            'Subject' => [
                'Charset' => $char_set,
                'Data' => $subject,
            ],
        ],
        // If you aren't using a configuration set, comment or delete the
        // following line
        'ConfigurationSetName' => $configuration_set,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}

我正在通过〜/ .aws / credential文件提供SDK的凭据,该文件包含访问ID密钥和秘密密钥。这是AWS CLI访问的同一文件,因此凭据似乎是正确的,并且可供CLI访问。

[default]
aws_access_key_id = AKIA2PK........Z72J3
aws_secret_access_key = co9r41j/i+QTrsA7244xG........KPH1LyBn34b

我在上面添加了“ ........”以保护我的访问和秘密访问密钥。

我收到以下错误消息,表明我的电子邮件尚未验证。但是它有!另外,我不在沙盒模式下。

“在“ https://email.us-west-2.amazonaws.com”上执行“ SendEmail”时出错; AWS HTTP错误:客户端错误:POST https://email.us-west-2.amazonaws.com导致400 Bad Request响应:发件人MessageReje (truncated...) MessageRejected (client): Email address is not verified. The following identities failed the check in region US-WEST-2: [email protected] - Sender MessageRejected电子邮件地址未验证。以下身份未能通过签入区域US-WEST-2:[email protected] dbbb0c1d-5493-4205-9257-a2fbb81eb5d9电子邮件未发送错误消息:电子邮件地址未验证以下身份未能在区域US-WEST-2中进行检查: [email protected]

关于如何调试它的任何想法?

感谢您可以提供的任何帮助。

标记

php amazon-web-services email amazon-ses
1个回答
0
投票

发现了问题。我希望这对其他AWS SDK用户有所帮助。 sdk凭据凭据提供程序为Web服务器用户找到了一个.aws / credentials文件,而不是从我的主目录中找到的。就我而言,查看文件/var/cache/nginx/.aws/credentials,找到一些为先前测试目的定义的凭据。

课程是,请注意aws sdk如何找到凭证文件。如果Web服务器用户设置了凭证文件,则它将优先使用该凭证文件,而不是$ HOME / .aws / credentials文件中的凭证文件。

© www.soinside.com 2019 - 2024. All rights reserved.