Most popular tags

26 questions

5 answers

1 comment

3,362 users

How to send email using amazon ses

0 like 0 dislike
664 views asked Dec 1, 2014 in PHP by patel.varun (1,060 points)
    

1 Answer

0 like 0 dislike

Step 1 - Copy required key from amazon

Get Public Key, Secret Key and Region frmo amazon console

 

Step 2 - Define constant or some configuration in your application

DEFINE("AWS_KEY", 'XXXXXXXXXXXXXX);
DEFINE("AWS_SECRET_KEY", 'XXXXXXXXXXXXXXXXXXXXXXXXXXX');
DEFINE("QWS_REGION", 'us-east-2');
 
Step 3 - Download and copy aws library and configure with your project
if you are using composer then use following code in your composer.json 
{
    "require": {
        "aws/aws-sdk-php": "dev-master"
    }
}

Step 3 - Create object of SesClient and pass keys to function

$sesClient = SesClient::factory(array(
   'key'    => AWS_KEY,
   'secret' => AWS_SECRET_KEY,
   'region' => QWS_REGION
));
 
Step 4 - Setup message and message properties
$msg['Source'] =  "from Email";
 
//ToAddresses must be an array
$msg['Destination']['ToAddresses'][] = array of your to email
$msg['Destination']['BccAddresses'][] = array of your BCC email
 
$msg['Message']['Subject']['Data'] = Your subject
$msg['Message']['Subject']['Charset'] = "UTF-8";
 
$msg['Message']['Body']['Text']['Data'] = $body;
$msg['Message']['Body']['Text']['Charset'] = "UTF-8";
 
 
eg. 
$msg = array();
 
$msg['Source'] =  "no-reply@example.com";
 
//ToAddresses must be an array
$msg['Destination']['ToAddresses'][] = array('email1@eample.com', 'email2@example.com');
$msg['Destination']['BccAddresses'][] = array('email1@eample.com', 'email2@example.com');
 
$msg['Message']['Subject']['Data'] = 'Testing subject';
$msg['Message']['Subject']['Charset'] = "UTF-8";
 
$msg['Message']['Body']['Text']['Data'] = 'Testing body content';
$msg['Message']['Body']['Text']['Charset'] = "UTF-8";
 
Step 5 - Send email
$result = $sesClient->sendEmail($msg);
 
 
answered Dec 16, 2014 by expert (2,200 points)

Related questions

0 like 0 dislike
0 answers 86 views
86 views asked Nov 27, 2014 in API by expert (2,200 points)
0 like 0 dislike
0 answers 74 views
0 like 0 dislike
0 answers 118 views
118 views asked Mar 14, 2015 in PHP by dpatil (1,140 points)
0 like 0 dislike
0 answers 201 views
201 views asked Apr 13, 2015 by dpatil (1,140 points)
0 like 0 dislike
1 answer 397 views
...