StefGuev
StefGuev

Reputation: 649

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 [email protected] with your "From" address. 
// This address must be verified with Amazon SES.
define('SENDER', '[email protected]');           

// Replace [email protected] with a "To" address. If your account 
// is still in the sandbox, this address must be verified.
define('RECIPIENT', '[email protected]');    

// 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!

Upvotes: 3

Views: 1519

Answers (2)

StefGuev
StefGuev

Reputation: 649

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

Upvotes: 1

Rez Moss
Rez Moss

Reputation: 4602

As far as I know PHP Mailer was not working with AWS SES by API, you should use SES SMTP with PHP Mailer.

The correct ports are 25, 465 or 587.

Upvotes: 0

Related Questions