0

I have set up AWS Ses service using PHP SDK:

$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'
    );
}

After trying to send email, I receive this error message:

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

Anyone know how to fix that error?

cUrl has support for SMTP, but smtp://email-smtp.eu-west-1.amazonaws.com throws error [curl] 1: Protocol smtp not supported or disabled in libcurl [url] smtp://email-smtp.eu-west-1.amazonaws.com/ cUrl

Justinas
  • 41,402
  • 5
  • 66
  • 96
  • That is a transport exception. AWS Ses Service should have shielded that one, report this as a bug upstream. – hakre Mar 29 '15 at 17:02
  • @hakre Do you know how to get around this exception? – Justinas Mar 29 '15 at 17:19
  • You can't. It's in there. It's thrown when applicable. You can catch it but instead you should report this problem upstream. – hakre Mar 29 '15 at 17:20

3 Answers3

0

You are not using a valid endpoint.

email-smtp.eu-west-1.amazonaws.com is the SMTP endpoint, not HTTPS. The HTTPS endpoint is email.eu-west-1.amazonaws.com.

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

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
0
  1. Use https://email.{$region}.amazonaws.com as base_url
    At this stage, i get error: 'User 'arn:aws:iam::######:user/ebpush' is not authorized to perform 'ses:SendEmail' on resource `arn:aws:ses:eu-west-1:447362101282:identity/verified@gmail.com'
  2. Add IAM > Groups > Create group > AmazonSESFullAccess
  3. Go to IAM > Policies > AmazonSESFullAccess > Attach > ebPush

OR

Use PHPMailer to connect via email-smtp.{region}.amazonaws.com where Username is your SES Access Key and password is your SES Secret Key

Justinas
  • 41,402
  • 5
  • 66
  • 96
0

You do not need to set the base_url/endpoint explicitly in AWS SDK for PHP. Setting the region will ensure the proper endpoint is used.

Jeremy Lindblom
  • 6,437
  • 27
  • 30