Sending emails to multiple receipients with Amazon SES
This post is more than 10 years old. I do not delete posts, because even old information is still useful, but please know that some material on this page may be outdated or incorrect. Thanks!
After reading through a ton of documentation posts and forum topics for Amazon SES about this issue, I finally found this post about the string list format that helped me be able to send an email with Amazon SES's sendmail API to multiple recipients.
Every way I tried getting this working, I was receiving errors like InvalidParameter for the sender, Unexpected list element termination for the error code, etc.
Normally, when sending email, you can either pass a single address or multiple addresses as a string, and you'll be fine:
- Single Address:
John Doe - Multiple Addresses:
John Doe, Jane Doe
...just add in a comma between each address, and you're golden. Amazon's SES API documentation says you can pass a 'string/array' for the 'ToAddresses' parameter, and those addresses will be sent an email. They're kinda lacking in implementation details, though, and it took some wrangling to find out that, using Amazon's PHP API class, I had to prepare my addresses like so:
For normal (single) email addresses, I could just go:
<?php
$destination = CFComplexType::map(array(
'ToAddresses' => 'John Doe <[email protected]>',
));
?>
(The $destination parameter would be passed into $ses->send_mail).
However, for multiple email addresses, you must pass in an array, with the following structure, and pass that to the CFComplexType object:
<?php
$to = array(
'member' => array(
0 => 'John Doe <[email protected]>',
1 => 'Jane Doe <[email protected]>',
),
);
$destination = CFComplexType::map(array(
'ToAddresses' => $to,
));
?>
I don't know why Amazon can't just accept a normal string with commas designating recipients, as that would make life easier, imo, but oh well.
Comments