Skip to content

Instantly share code, notes, and snippets.

@SumonMSelim
Created September 20, 2023 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SumonMSelim/0abb6d5c2978843a972081ae20cae9e3 to your computer and use it in GitHub Desktop.
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.
<?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