Skip to content

Instantly share code, notes, and snippets.

@aksyuma
Created March 24, 2020 16:14
Show Gist options
  • Select an option

  • Save aksyuma/ba6dae7681c3ae04debd37dd7ef57cab to your computer and use it in GitHub Desktop.

Select an option

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.
<?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());
}
?>
@inglesuniversal
Copy link

Hello, do you happen to have a PHP example for pinpoint voice messages. It's been very hard finding a working example. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment