- Download as zip with command
curl -LJO https://gist.github.com/kangks/eda238bdee360070244ff9e53fc71312/archive/7ae513002e69388b438dd2b3e6994b9d2abbb801.zip
- Extract and run
docker-compose up
from the folder - For first run, wait for the composer to finish download all dependencies
- Open a browser and enter
http://localhost/pinpoint.php
as the url
Last active
October 31, 2023 14:01
-
-
Save kangks/eda238bdee360070244ff9e53fc71312 to your computer and use it in GitHub Desktop.
AWS PinpointEmailClient with SDK for PHP
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
{ | |
"require": { | |
"aws/aws-sdk-php": "^3.209" | |
}, | |
"autoload": { | |
"psr-0": { | |
"": "*" | |
}, | |
"psr-4": { | |
"Aws\\Resource\\": "src/" | |
} | |
} | |
} |
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
version: "3.7" | |
services: | |
php: | |
image: arm64v8/php:8.1.25-apache-bullseye | |
ports: | |
- 80:80 | |
volumes: | |
- ./aws_credentials:/.aws | |
- .:/var/www/html | |
composer: | |
image: composer:1.9 | |
command: ["composer", "install"] | |
volumes: | |
- .:/app |
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\Exception\AwsException; | |
use Aws\PinpointEmail\PinpointEmailClient; | |
$settings = (array( | |
'profile' => 'pinpoint', | |
'region' => 'us-east-1', | |
'version' => '2018-07-26', | |
)); | |
$pinpointClient = new Aws\PinpointEmail\PinpointEmailClient($settings); | |
?> | |
<?php | |
# The "From" address. This address has to be verified in Amazon Pinpoint in the region you're using to send email. | |
$SENDER = "[email protected]"; | |
# The addresses on the "To" line. If your Amazon Pinpoint account is in the sandbox, these addresses also have to be verified. | |
$TOADDRESS = "[email protected]"; | |
?> | |
<form method="post"> | |
From: <input type="text" name="SENDER" value="<?php echo $SENDER;?>"> | |
To: <input type="text" name="TOADDRESS" value="<?php echo $TOADDRESS;?>"> | |
<input type="radio" name="content" value="simple">Simple | |
<input type="radio" name="content" value="template">Template | |
<input type="submit" name="send" value="Send Email"/> | |
</form> | |
<br/> | |
<br/> | |
<?php | |
// https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-pinpoint-email-2018-07-26.html#sendemail | |
if(isset($_POST['send'])) { | |
$selected_content = $_POST['content']; | |
$content = ''; | |
if ($selected_content == 'simple') { | |
$content = array( | |
'Simple' => [ | |
'Body' => [ // REQUIRED | |
'Html' => [ | |
'Charset' => 'utf8', | |
'Data' => 'click <a href="https://doit.com/">here</a>', // REQUIRED | |
] | |
], | |
'Subject' => [ // REQUIRED | |
'Charset' => 'utf8', | |
'Data' => 'from Pinpoint', // REQUIRED | |
], | |
]); | |
} else if ($selected_content == 'template') { | |
$content = array( | |
'Template' => [ | |
'TemplateArn' => 'arn:aws:mobiletargeting:<AWS Region>:<AWS Account ID>:templates/template/EMAIL', | |
'TemplateData' => json_encode (new stdClass) | |
] | |
); | |
}; | |
try { | |
$result = $pinpointClient->sendEmail([ | |
'Content' => | |
$content, | |
'Destination' => [ | |
'ToAddresses' => [$TOADDRESS], | |
], | |
'FromEmailAddress' => $SENDER | |
]); | |
print $result; | |
} catch (AwsException $e){ | |
error_log($e->getMessage()); | |
} | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment