My site is using ses for the smtp service. To use that I tried following configuration in config file.
With the above configuration, its expected that the mail is sent from the server. But no mail is getting send from server.
I tried same smtp settings with phpmailer which is sending the mails successfully and I am receiving it.
Even with simple mail() function mails are gettiing delivered. But not when setting the config values to "sendmail" or "smtp". Any idea?
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.
- Nikolai Shcherbin@rivervanrain

Nikolai Shcherbin - 0 likes
- Reuven@reuven

Reuven - 0 likes
<?php require_once(dirname(__FILE__) . '/Amazon-AWS-SDK/aws-autoloader.php'); use Aws\Ses\SesClient; use Aws\Ses\Exception\SesException; elgg_register_event_handler('init', 'system', 'amazon_ses_init'); function amazon_ses_init() { elgg_register_plugin_hook_handler('email', 'system', 'amazon_ses_send_email'); } function amazon_ses_send_email($hook, $type, $returnvalue, $params) { if (!is_array($returnvalue) || !is_array($returnvalue['params'])) { 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; } $subject = $returnvalue['subject']; $from = $returnvalue['from']; $site_url = elgg_get_site_url(); $notification_settings_url = $site_url . '/notifications/personal/' . $recipient->username; $group_notification_settings_url = $site_url . '/notifications/group/' . $recipient->username; $recipient_language = ($recipient->language) ? $recipient->language : (($site_language = elgg_get_config('language')) ? $site_language : 'en'); $originalMessage = $returnvalue['body']; /** ===== Prepare the HTML message ====== */ $messageHTML = $originalMessage.elgg_echo('amazon_ses:content', [$to_address, $site_url, $notification_settings_url, $group_notification_settings_url], $recipient_language); /** ===== Prepare the TEXT message ====== * ======= remove HTML tags =============== */ $messageTEXT = preg_replace('/<.*?>/s', '', $messageHTML); /** ===== replace non-breaking space with regular space =============== */ $messageTEXT = preg_replace('/ /', ' ', $messageTEXT); /** ===== Amazon SES Starts ===== */ $client = SesClient::factory([ 'version'=> 'latest', 'region' => 'us-east-1' ]); $charset = 'UTF-8'; try { if(preg_match('/<.*?>/s',$originalMessage)){// == if there are HTML tags send HTML and TEXT emails $result = $client->sendEmail([ 'Destination' => [ 'ToAddresses' => [ $to_address, ], ], 'Message' => [ 'Body' => [ 'Html' => [ 'Charset' => $charset, 'Data' => $messageHTML, ], 'Text' => [ 'Charset' => $charset, 'Data' => $messageTEXT, ], ], 'Subject' => [ 'Charset' => $charset, 'Data' => $subject, ], ], 'Source' => $from, ]); }else{// === If no HTML tags - send only TEXT email $result = $client->sendEmail([ 'Destination' => [ 'ToAddresses' => [ $to_address, ], ], 'Message' => [ 'Body' => [ 'Text' => [ 'Charset' => $charset, 'Data' => $messageTEXT, ], ], 'Subject' => [ 'Charset' => $charset, 'Data' => $subject, ], ], 'Source' => $from, ]); } $messageId = $result->get('MessageId'); return true; } catch (SesException $error) { $errorMessage = $error->getAwsErrorMessage(); $message .= $messageTEXT.' ..... send by mail.'; $headers = "From: $from"; if(mail($to_address,$subject,$message,$headers)!==false){ return true; } } return $returnvalue; }
- Sarath@sarathsince85

Sarath - 0 likes
- Sarath@sarathsince85

Sarath - 0 likes
You must log in to post replies.Fix this piece and try again:
Read also this discussion - perhaps, you will find there something useful for you.
With the help of iionly I've developed a plugin that works well with Amazon ses, for elgg 2.3.14
All the relevant code is in start.php (below). Also, you need to install the appropriate Amazon AWS sdk.
Hope it help you.
@Nikolai: tried all those permutations and combinations before posting the ticket :)
@Reuven: Thanks a lot for that. Let me give it a try.
@Reuven: Thanks for that script. That was a good starting point for me. I modified this and used Cash's php mailer plugin too to connect to SES via smtp. Now its working in Elgg 2.3 branch.