I've built a simple plugin to integrate Amazon SES SDK, but it does not work.
example.com/members/mod/amazon/start.php
<?php
elgg_register_event_handler('init', 'system', 'amazon_ses_init');
function amazon_ses_init() {
elgg_register_plugin_hook_handler('email', 'system', function($hook, $type, $returnvalue, $params) {
if ($returnvalue === true) {
return;
}
$to_address = '';
$contact = $returnvalue['to'];
$containsName = preg_match('/<(.*)>/', $contact, $matches) == 1;
if ($containsName) {
$to_address = $matches[1];
} else {
$to_address = $contact;
}
if (!$to_address) {
return $returnvalue;
}
$users = get_user_by_email($to_address);
$recipient = $users[0];
if (!($recipient instanceof ElggUser)) {
return $returnvalue;
}
$message = $returnvalue['body'];
$subject = $returnvalue['subject'];
$from = $returnvalue['from'];
/** ==========AMAZON SES (comment/uncomment) ====================== */
include_once(dirname(__FILE__) . '/functions/amazonSes.php');
mailAmazonSES($to_address,$from,$subject,$message);
/** ==========mail PHP (uncomment/comment)====================== */
/*$headers = "From: $from";
mail($to_address,$subject,$message,$headers);*/
return true;
});
}
<?php
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
function mailAmazonSES($to,$from,$subject,$textMSG) {
include_once './Amazon-AWS-SDK/aws-autoloader.php';
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => 'us-east-1'
));
$charset = 'UTF-8';
try {
$result = $client->sendEmail([
'Destination' => [
'ToAddresses' => [
$to,
],
],
'Message' => [
'Body' => [
'Text' => [
'Charset' => $charset,
'Data' => $textMSG,
],
],
'Subject' => [
'Charset' => $charset,
'Data' => $subject,
],
],
'Source' => $from,
]);
$messageId = $result->get('MessageId');
//echo("Email sent! Message ID: $messageId"."\n");
} catch (SesException $error) {
//echo("The email was not sent. Error message: ".$error->getAwsErrorMessage()."\n");
}
}
<?php
include_once(dirname(__FILE__) . '/functions/amazonSes.php');
$from = 'noreply@example.com';
$to_address = 'zelinkovsky@gmail.com';
$subject = "My Test Subject";
$textMSG = "Dear Text Friend,\r\nThis email was send with Amazon SES using the AWS SDK for PHP";
mailAmazonSES($to_address,$from,$subject,$textMSG);
?>
It works well when I try to call the SDK directly through example.com/members/mod/amazon/amazon-test.php
When I try the start.php with mail php (see at the bottom of start.php) it works well.
However, it does not work when I try start.php with the function mailAmazonSES
Please advise
Thank you
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
Dear Magician iionly :)
Works like a charm !! - Thank you very much.
I wish I understand what you have done.
Anyway, I turned on "Warnings and errors" but I cannot find the error log??
Thank you again - you made my day :)
Maybe the new position of the namespace is the reason ??
- Previous
- 1
- 2
- Next
You must log in to post replies.