lundi 2 mars 2015

How to send mail through php mail on Amazon SES service?

I want to send mail through php mail on Amazon SES service, In using PHP Mail But I am not able to send send. I already verify the my email_id. I am using this tutorial as reference http://ift.tt/1CigOaJ


sendMail.php



<?php
require 'AWSSDKforPHP/aws.phar';

use Aws\Ses\SesClient;
$client = SesClient::factory(array(
'key' => 'aws_key',
'secret' => 'aws_secret',
'region' => 'us-east-1'
));

//Now that you have the client ready, you can build the message
$msg = array();
$msg['Source'] = "sender@gmail.com";// Verified Sender
//ToAddresses must be an array
$msg['Destination']['ToAddresses'][] = "receiver@gmail.com";// Verified Receiver

$msg['Message']['Subject']['Data'] = "Text only subject";
$msg['Message']['Subject']['Charset'] = "UTF-8";

$msg['Message']['Body']['Text']['Data'] ="Text data of email";
$msg['Message']['Body']['Text']['Charset'] = "UTF-8";
$msg['Message']['Body']['Html']['Data'] ="HTML Data of email<br />";
$msg['Message']['Body']['Html']['Charset'] = "UTF-8";

try{
$result = $client->sendEmail($msg);

//save the MessageId which can be used to track the request
$msg_id = $result->get('MessageId');
echo("MessageId: $msg_id");

//view sample output
print_r($result);
} catch (Exception $e) {
//An error happened and the email did not get sent
echo($e->getMessage());
}
//view the original message passed to the SDK
print_r($msg);
?>


I include the above file in the following code, which is used to insert info into data base, When Any new entry comes for customer, we have to send one email to customer.


Booking.php



<?php
header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
mysql_connect("localhost","****","***");
mysql_select_db("bookingService");

if(isset($_POST['type']))
{
if($_POST['type']=="booking"){
$name = $_POST ['Name'];
$mobile = $_POST ['Mob_Num'];
$mail = $_POST ['Email'];
$comments=$_POST ['comments'];
$query = "insert into customer(userName, userContactNumber, email, comments) values('$name','$mobile','$mail', '$comments')";
$result=mysql_query($query);
$id=mysql_insert_id();
//$value = "Welcome Mr/Mrs ".$name." Thanks for booking home services your booking id is = ".$id;
require ('sendMail.php');
//echo json_encode($value);
}
}
else{
echo "Invalid format";
}
?>


sendMail.php and Booking.php are in same directory.





Aucun commentaire:

Enregistrer un commentaire