Skip to content

Commit

Permalink
Add support for Configuration set and Message tags; Fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Zahariev committed Jan 5, 2018
1 parent 5fe5cae commit 093c23a
Show file tree
Hide file tree
Showing 5 changed files with 676 additions and 423 deletions.
Empty file added .gitignore
Empty file.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ $m->addAttachmentFromFile('logo.png','path/to/logo.png','application/octet-strea

```

### Configuration Set and Message Tags
```php
<?php

// Set the configuration set
$m->setConfigurationSet('myConfigurationSet');

// Reset the configuration set
$m->setConfigurationSet(null);


// Set message tag
$m->setMessageTag('key', 'value');

// Get message tag
$tag = $m->getMessageTag('key');

// Remove message tag
$m->removeMessageTag('key');

// Set message tags in bulk - performs merge with current tags
$m->setMessageTags(array('key1' => 'value1', 'key2' => 'value2'));

// Get message tags
$tags = $m->getMessageTags();

// Remove all message tags
$m->removeMessageTags();

```


### Sending Bulk Messages
When hundreds of emails have to be sent in bulk it's best to use the Bulk mode which essentially reuses a CURL handler and reduces the number of SSL handshakes and this gives a better performance.

Expand Down Expand Up @@ -183,6 +215,16 @@ $ses->sendEmail($m, $use_raw_request, $trigger_error);


### Changelog
v.0.9.1
- Added support for AWS SES Configuration Sets and Message Tags
- Added caching mechanism in `SimpleEmailServiceMessage` to speed up bulk sending mode

v.0.9.0
- Add parameter for raw message encoding

v.0.8.9
- Merge pull request 32 from hlev/remove-to-requirement

v.0.8.8

- Issues fixed: #24, #25, #30, #31
Expand Down
15 changes: 14 additions & 1 deletion src/SimpleEmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*
* @link https://github.com/daniel-zahariev/php-aws-ses
* @package AmazonSimpleEmailService
* @version v0.8.9
* @version v0.9.1
*/
class SimpleEmailService
{
Expand Down Expand Up @@ -381,7 +381,13 @@ public function sendEmail($sesMessage, $use_raw_request = false , $trigger_error
$action = !empty($sesMessage->attachments) || $use_raw_request ? 'SendRawEmail' : 'SendEmail';
$ses_request->setParameter('Action', $action);

// Works with both calls
if (!is_null($sesMessage->configuration_set)) {
$ses_request->setParameter('ConfigurationSetName', $sesMessage->configuration_set);
}

if($action == 'SendRawEmail') {
// https://docs.aws.amazon.com/ses/latest/APIReference/API_SendRawEmail.html
$ses_request->setParameter('RawMessage.Data', $sesMessage->getRawMessage());
} else {
$i = 1;
Expand Down Expand Up @@ -441,6 +447,13 @@ public function sendEmail($sesMessage, $use_raw_request = false , $trigger_error
$ses_request->setParameter('Message.Body.Html.Charset', $sesMessage->messageHtmlCharset);
}
}

$i = 1;
foreach($sesMessage->message_tags as $key => $value) {
$ses_request->setParameter('Tags.member.'.$i.'.Name', $key);
$ses_request->setParameter('Tags.member.'.$i.'.Value', $value);
$i++;
}
}

$ses_response = $ses_request->getResponse();
Expand Down
Loading

0 comments on commit 093c23a

Please sign in to comment.