Created
March 24, 2020 16:14
-
-
Save aksyuma/ba6dae7681c3ae04debd37dd7ef57cab to your computer and use it in GitHub Desktop.
A php script that uses AWS PHP SDK v3 for Amazon Pinpoint service to send an email message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'vendor/autoload.php'; | |
| use Aws\Pinpoint\PinpointClient; | |
| use Aws\Exception\AwsException; | |
| /** | |
| * @author syumaK(Amos Syuma) | |
| * Date: March 24, 2020 | |
| * Description: A php script that uses AWS PHP SDK for Pinpoint service to send an email message. | |
| * | |
| */ | |
| /** | |
| * This code expects that you have AWS credentials set up per: | |
| * https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html | |
| */ | |
| // Instantiate a client with the credentials from the credential profiles (.aws/credentials) file. | |
| $settings = (array( | |
| 'profile' => 'syumaK', | |
| 'region' => 'us-east-1', | |
| 'version' => 'latest', | |
| )); | |
| $pinpointClient = new Aws\Pinpoint\PinpointClient($settings); | |
| # The "From" address. This address has to be verified in Amazon Pinpoint in the region you're using to send email. | |
| $SENDER = "redacted"; | |
| # The addresses on the "To" line. If your Amazon Pinpoint account is in the sandbox, these addresses also have to be verified. | |
| $TOADDRESS = "redacted"; | |
| try { | |
| $result = $pinpointClient->sendMessages([ | |
| 'ApplicationId' => '4fd13xxxxxxxxx', // REQUIRED | |
| 'MessageRequest' => [ // REQUIRED | |
| 'Addresses' => [ | |
| $TOADDRESS => [ | |
| 'ChannelType' => 'EMAIL', | |
| ], | |
| ], | |
| 'MessageConfiguration' => [ // REQUIRED | |
| 'EmailMessage' => [ | |
| 'FromAddress' => $SENDER, | |
| ], | |
| ], | |
| 'TemplateConfiguration' => [ // REQUIRED | |
| 'EmailTemplate' => [ | |
| 'Name' => 'One', | |
| 'Version' => '1', | |
| ], | |
| ], | |
| ], | |
| ]); | |
| print $result; | |
| } catch (AwsException $e){ | |
| // output error message if fails | |
| error_log($e->getMessage()); | |
| } | |
| ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, do you happen to have a PHP example for pinpoint voice messages. It's been very hard finding a working example. Thanks