NewbieSSProgrammer NewbieSSProgrammer - 2 months ago 23
PHP Question

Amazon SES PHPMail or SDK

I've registered with Amazon SES service with email limit setup and out of the sandbox. I've tried many PHPMailer function and all return me as error : Connexion time out (110). Is it possible the send mail from PHPMailer?

I have seen on Amazon SES site this link.

<?php

// Replace path_to_sdk_inclusion with the path to the SDK as described in
// http://docs.aws.amazon.com/aws-sdk-php/v2/guide/quick-start.html
define('REQUIRED_FILE','path_to_sdk_inclusion');

// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'sender@example.com');

// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'recipient@example.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 Aws\Ses\SesClient;

$client = SesClient::factory(array(
'version'=> 'latest',
'region' => REGION
));

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

?>


I've copy all the codes, put my variable instead of showned in the demo script. Now I'm getting the error : You must use KEY ans SECRET_KEY to use this script... Where I cant put my KEY and SECRETKEY in the script? There is no explanation on how to do this.

Is there another way send email throught Amazon SES service?
Thanks!

Answer

So simple. I have to add key and secret in :

$client = SesClient::factory(array(
    'version'=> 'latest',     
    'region' => REGION,
     'credentials' => array(
        'key'    => 'XXXXXXXXXXXXXXXX',
        'secret' => 'XXXXXXXXXXXXXXXX',
    )
));

and set XXXXXXXXXXXXXXXX full access to api in amazon security credentials