AWS SES Guzzle发送电子邮件时出错

时间:2015-03-29 16:57:44

标签: php amazon-web-services aws-php-sdk

我使用PHP SDK设置了AWS Ses服务:

$this->client = SesClient::factory([
    'key' => $params['key'],
    'secretKey' => $params['secret_key'],
    'region' => 'eu-west-1',
    'base_url' => 'https://email-smtp.eu-west-1.amazonaws.com',
]);

$this->client->sendEmail($this->params());

public function params() {
    array(
        'Source' => 'verified@gmail.com',
        'Destination' => array(
            'ToAddresses' => array('receiver@yahoo.com')
        ),
        'Message' => array(
            'Subject' => array(
                'Data' => 'SES Testing',
                'Charset' => 'UTF-8',
            ),
            // Body is required
            'Body' => array(
                'Text' => array(
                    'Data' => 'My plain text email',
                    'Charset' => 'UTF-8',
                ),
                'Html' => array(
                    'Data' => '<b>My HTML Email</b>',
                    'Charset' => 'UTF-8',
                ),
            ),
        ),
        'ReplyToAddresses' => array( 'replyTo@email.com' ),
        'ReturnPath' => 'bounce@email.com'
    );
}

尝试发送电子邮件后,收到以下错误消息:

exception 'Guzzle\Http\Exception\CurlException' with message 
'[curl] 23: Failed writing body (0 != 86) [url] https://email-smtp.eu-west-1.amazonaws.com/' 
in C:\xampp\htdocs\myProject\protected\lib\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:338

任何人都知道如何修复该错误?

cUrl支持SMTP,但smtp://email-smtp.eu-west-1.amazonaws.com引发错误[curl] 1: Protocol smtp not supported or disabled in libcurl [url] smtp://email-smtp.eu-west-1.amazonaws.com/ cUrl

3 个答案:

答案 0 :(得分:0)

您没有使用有效的端点。

email-smtp.eu-west-1.amazonaws.com是SMTP端点,而不是HTTPS。 HTTPS端点为email.eu-west-1.amazonaws.com

http://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region

答案 1 :(得分:0)

  1. 使用https://email.{$region}.amazonaws.com作为base_url
    在这个阶段,我得到错误:&#39;用户&#39; arn:aws:iam :: ######:user / ebpush&#39;未被授权执行以下操作:SendEmail&#39;关于资源`arn:aws:ses:eu-west-1:447362101282:identity/verified@gmail.com'
  2. 添加 IAM &gt; 群组&gt; 创建论坛&gt; AmazonSESFullAccess
  3. 转到 IAM &gt; 政策&gt; AmazonSESFullAccess &gt; 附加&gt; ebPush
  4. 使用PHPMailer通过email-smtp.{region}.amazonaws.com连接,其中Username是您的SES访问密钥,密码是您的SES密钥

答案 2 :(得分:0)

您无需在AWS SDK for PHP中显式设置base_url / endpoint。设置区域将确保使用正确的端点。