Daniel Gafitescu Freelance web developer focused on open source solutions


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 (3) 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

  2. same problem here, with PhoneNumber I have the error InvalidParameter (client): Invalid parameter: PhoneNumber Reason: +15255xxxxxxxx is not valid to publish to –

  3. When using it. I got the error SnsClient class not found. I am using codeigniter for it.

Leave a comment

No trackbacks yet.