user4615324
user4615324

Reputation:

Amazon SNS - aws-sdk-php

I'm using the AWS SDK for PHP - Version 3.
The code below works well when I'm sending a single SMS message except the attribute DefaultSenderID which is not working when I send a SMS to a mobile device.

Amazon documentation says that DefaultSenderID – A string, such as your business brand, that is displayed as the sender on the receiving device. Support for sender IDs varies by country. The sender ID can be 1 - 11 alphanumeric characters, and it must contain at least one letter.

Has anyone experienced this problem using the Amazon SNS?

 $accessKey = 'XZA...';
 $accessSecret = 'YKW...';
 $credentials = new Aws\Credentials\Credentials($accessKey, $accessSecret);

 $sharedConfig = [
    'region'  => 'us-east-1',          
    'version' => 'latest',
    'credentials' => $credentials
];

 $sdk = new Aws\Sdk($sharedConfig);
 $sns = new SnsClient($sharedConfig);

 $payload = [
    'PhoneNumber' => '+999999999',   // E.164 format
    'Message' => md5(time()),
    'MessageAttributes' => [
      'DefaultSenderID' => ['DataType'=>'String','StringValue'=>'MyBrandName'],
      'DefaultSMSType' => ['DataType'=>'String','StringValue'=>'Transactional']
    ]
];

try {
    $data = $sns->publish( $payload );
    $MessageId = $data->get('MessageId');
} catch ( Exception $e ) {   }

Upvotes: 1

Views: 1076

Answers (1)

tomfrio
tomfrio

Reputation: 1034

For anybody still struggling with this.

If you look at the documentation here, you will find that you need to add the key AWS.SNS.SMS.SenderID to the payload's MessageAttributes.

The following should work:

$payload = [
    'PhoneNumber' => '+999999999', // E.164 format
    'Message' => md5(time()),
    'MessageAttributes' => [
        'AWS.SNS.SMS.SenderID' => [
            'DataType' => 'String',
            'StringValue' => 'YourSenderID',
        ]
    ]
];

try {
    $data = $sns->publish($payload);
    $MessageId = $data->get('MessageId');
} catch (Exception $e) { }

Upvotes: 1

Related Questions