Daniel Gafitescu Freelance web developer focused on open source solutions

30Jun/161

Send SMS using AWS SNS

Usually I go with Twillio for sending SMS but AWS has a cheaper and easier solution for this.
Here is the code to send a sms using AWS SNS

First thing install aws/aws-sdk-php package

require __DIR__.'/../vendor/autoload.php';

use Aws\Sns\SnsClient;
$client = SnsClient::factory([
    'credentials' => [
            'key'    => 'your key',
            'secret' => 'your secret',
        ],
    'region'  => 'us-west-2',
    'version' => "latest"
]);

$sent = $client->publish(
    [
        'Message' => 'This is the message',
        'PhoneNumber' => '+123344545',
        'MessageAttributes' => [
            'AWS.SNS.SMS.SenderID' => [
                'DataType' => 'String',
                'StringValue' =>  'The sender'
            ]
        ]
    ]
);

 

Tagged as: , , Leave a comment
Comments (1) Trackbacks (0)
  1. I use this code. If i call publish with ‘PhoneNumber’ , I get the AWS Error Message Invalid Parameter: Topic Arn or TargetArn Reason : no value for required paramter.

    But if i use a topicArn with my mobile phone number subscribed to this topic , I’m able to send SMS messages.

    You think I’m missing something.
    - Deepak


Leave a comment

No trackbacks yet.