I want to setup an asynchronous email service via amazon simple email service, but i've some big problems:
new Ajax.Request('https://email.us-east-1.amazonaws.com/?Action=SendEmail&Source=myemail@domain.com&Destination.ToAddresses.member.1=mydestination@domain.com&Message.Subject.Data=This%20is%20the%20subject%20line.&Message.Body.Text.Data=Hello.%20I%20hope%20you%20are%20having%20a%20good%20day.',
{
method: 'get',
requestHeaders: {"Date": +res["result"]["date"],
"X-Amzn-Authorization":"AWS3-HTTPS",
"AWSAccessKeyId":"myaccesskey",
"SignatureMethod":"mysignature"
"Signature":+res["开发者_开发百科result"]["auth"]},
i have an 403 error so i'm wondering what's happened from amazon.
Date is gmdate('D, d M Y H:i:s e')
and is correct.
Signature come from hash_hmac('sha256', $date, 'exampleofsignature', false));
Could you help me please. I really appreciate that you post examples.
If you leverage the AWS SDK for PHP to handle all of the low-level details like request signing, this function will accomplish what you're trying to do.
<?php
/**
* Send a plain-text email using Amazon SES.
*
* @link http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonSES/send_email AmazonSES::send_email()
* @param string|array $to (Required) The email address(es) to send to. Accepts a string for one, or an array for multiple.
* @param string $from (Required) The email address of the sender.
* @param string $subject (Required) The subject of the email. US-ASCII characters only!
* @param string $message (Required) The plain-text email to send. US-ASCII characters only!
* @return boolean Whether the request was successful or not.
*/
function send_text_email($to, $from, $subject, $message)
{
$email = new AmazonSES(AWS_KEY, AWS_SECRET_KEY);
$response = $email->send_email($from, //Source (aka From)
array('ToAddresses' => $to), // Destination (aka To)
array( // Message (short form)
'Subject.Data' => $subject,
'Body.Text.Data' => $message
)
);
return $response->isOK(); // boolean
}
?>
i finally bypassing the problem.
Here's the code:
$headers = array();
$headers[]= "X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=XXXXXXXXXXXXXX, Algorithm=HmacSHA256, Signature=".$auth;
$headers[]= "Date: ".$date;
$curl = curl_init('https://email.us-east-1.amazonaws.com/?Action=SendEmail&Source=contact@enterprise.com&Destination.ToAddresses.member.1='.$contact['email'].'&Message.Subject.Data='.rawurlencode($subject).'&Message.Body.Text.Data='.rawurlencode($body));
curl_setopt($curl, CURLOPT_USERAGENT, 'anUserAgent');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
if (curl_exec($curl)) {
S('log')->debug(curl_getinfo($curl, CURLINFO_HTTP_CODE));
} else {
S('log')->debug(curl_error($curl));
}
... i execute this code behind an javascript button action providing a form
精彩评论