Created
September 20, 2023 19:47
-
-
Save SumonMSelim/0abb6d5c2978843a972081ae20cae9e3 to your computer and use it in GitHub Desktop.
Sends a text message (SMS message) directly to a phone number using Amazon SNS.
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 | |
use Aws\Sns\SnsClient; | |
use Aws\Exception\AwsException; | |
/** | |
* Sends a text message (SMS message) directly to a phone number using Amazon SNS. | |
* | |
* 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 | |
*/ | |
$SnSclient = new SnsClient([ | |
'region' => 'us-east-1', | |
'version' => '2010-03-31' | |
]); | |
$message = 'This message is sent from an Amazon SNS code sample.'; | |
$phone = '+1XXX5550100'; | |
try { | |
$result = $SnSclient->publish([ | |
'Message' => $message, | |
'PhoneNumber' => $phone, | |
]); | |
var_dump($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