【问题标题】:Getting a 403 error while trying to setup AMAZON SES尝试设置 AMAZON SES 时出现 403 错误
【发布时间】:2011-07-05 23:23:48
【问题描述】:

我想通过亚马逊简单的电子邮件服务设置一个异步电子邮件服务,但我有一些大问题:

new Ajax.Request('https://email.us-east-1.amazonaws.com/?Action=SendEmail&Source=myemail@domain.com&Destination.ToAddresses.member.1=mydestination@domain.com&Message.Subject.Data=This%20is%20the%20subject%20line.&Message.Body.Text.Data=Hello.%20I%20hope%20you%20are%20having%20a%20good%20day.',
    {
   method: 'get',
   requestHeaders: {"Date": +res["result"]["date"],
                    "X-Amzn-Authorization":"AWS3-HTTPS",
                    "AWSAccessKeyId":"myaccesskey",
                    "SignatureMethod":"mysignature"
                    "Signature":+res["result"]["auth"]},

我有一个 403 错误,所以我想知道亚马逊发生了什么。

日期是gmdate('D, d M Y H:i:s e') 并且是正确的。 签名来自hash_hmac('sha256', $date, 'exampleofsignature', false));

请你帮帮我。非常感谢您发布示例。

【问题讨论】:

    标签: php installation amazon prototypejs


    【解决方案1】:

    如果您利用AWS SDK for PHP 来处理请求签名等所有低级细节,此函数将完成您正在尝试做的事情。

    <?php
    /**
     * Send a plain-text email using Amazon SES.
     *
     * @link http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonSES/send_email AmazonSES::send_email()
     * @param string|array $to (Required) The email address(es) to send to. Accepts a string for one, or an array for multiple.
     * @param string $from (Required) The email address of the sender.
     * @param string $subject (Required) The subject of the email. US-ASCII characters only!
     * @param string $message (Required) The plain-text email to send. US-ASCII characters only!
     * @return boolean Whether the request was successful or not.
     */
    function send_text_email($to, $from, $subject, $message)
    {
        $email = new AmazonSES(AWS_KEY, AWS_SECRET_KEY);
        $response = $email->send_email($from, //Source (aka From)
            array('ToAddresses' => $to), // Destination (aka To)
            array( // Message (short form)
                'Subject.Data' => $subject,
                'Body.Text.Data' => $message
            )
        );
        return $response->isOK(); // boolean
    }
    ?>
    

    【讨论】:

      【解决方案2】:

      我终于绕过了这个问题。

      代码如下:

      $headers = array();
          $headers[]= "X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=XXXXXXXXXXXXXX, Algorithm=HmacSHA256, Signature=".$auth;
          $headers[]= "Date: ".$date;
          $curl = curl_init('https://email.us-east-1.amazonaws.com/?Action=SendEmail&Source=contact@enterprise.com&Destination.ToAddresses.member.1='.$contact['email'].'&Message.Subject.Data='.rawurlencode($subject).'&Message.Body.Text.Data='.rawurlencode($body));
            curl_setopt($curl, CURLOPT_USERAGENT, 'anUserAgent');
            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
          if (curl_exec($curl)) {
            S('log')->debug(curl_getinfo($curl, CURLINFO_HTTP_CODE));
          } else {
            S('log')->debug(curl_error($curl));
          }
      

      ...我在提供表单的 javascript 按钮操作后面执行此代码

      【讨论】:

        猜你喜欢
        • 2016-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-19
        • 2017-04-25
        • 2020-10-01
        • 1970-01-01
        相关资源
        最近更新 更多