Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending SMS with Amazon AWS services PHP

I'm having trouble digging through the documentation for Amazon's AWS PHP-sdk.

Basically, I just need to send a standard text message to a number. I know it is possible because amazon allows you to send messages through the console directly via this screen:

Amazon Console SMS

It says something about using the "publish" method, but looking through that documentation really didn't provide any answers. #Publish documentation link

Any help or guidance is appreciated. I am currently looking for a solution that uses V2 of the sdk.

Thanks in advance.

like image 359
Imperialized Avatar asked Aug 03 '16 19:08

Imperialized


People also ask

How do I send a text message to Amazon?

To chat with Amazon customer service on the mobile app, tap the three-line icon in the bottom-right corner of your screen and go to Customer Service > Get help with something else > Something else > I need more help. Finally, type in the chat box at the bottom of your screen and tap Send.

Does PHP work with AWS?

PHP on AWSSimplifies use of AWS services by providing a set of libraries that are consistent and familiar for PHP developers. A Laravel plugin that integrates AWS services with your application using the latest version of AWS SDK For PHP.

Can PHP send text messages?

To send an SMS through PHP to Mr. Example, you could simply add [email protected] to any email client, type a message, and hit send. This will send a text message to phone number +1 (385) 555-0168 on the Verizon Wireless Network.


1 Answers

No where have a doc showing it to use with PHP. Reading the Java and C# sdk I wrote the PHP version that works.

Updated on dec 20 '18

The args passed to publish method now have a new format. Fixed!

How to send a SMS over AWS using PHP

First install aws/aws-sdk-php. Using composer:

composer require aws/aws-sdk-php

Create a php file with:

require './vendor/autoload.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);

$params = array(
    'credentials' => array(
        'key' => 'YOUR_KEY_HERE',
        'secret' => 'YOUR_SECRET_HERE',
    ),
    'region' => 'us-east-1', // < your aws from SNS Topic region
    'version' => 'latest'
);
$sns = new \Aws\Sns\SnsClient($params);

$args = array(
    "MessageAttributes" => [
                'AWS.SNS.SMS.SenderID' => [
                    'DataType' => 'String',
                    'StringValue' => 'YOUR_SENDER_ID'
                ],
                'AWS.SNS.SMS.SMSType' => [
                    'DataType' => 'String',
                    'StringValue' => 'Transactional'
                ]
            ],
    "Message" => "Hello World! Visit www.tiagogouvea.com.br!",
    "PhoneNumber" => "FULL_PHONE_NUMBER"
);


$result = $sns->publish($args);
echo "<pre>";
var_dump($result);
echo "</pre>";

The result must have one array with many data, including MessageId.

like image 200
Tiago Gouvêa Avatar answered Sep 29 '22 00:09

Tiago Gouvêa