Thomas
Thomas

Reputation: 313

SenderID using Amazon Web Services PHP SDK

I'm trying to send an SMS through my PHP site using the AWS SDK. I use the code from Sending SMS with Amazon AWS services PHP.

require $_SERVER['DOCUMENT_ROOT'] . '/inc/aws/aws-autoloader.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);

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

$args = array(
"SenderID" => "TestSender",
"SMSType" => "Transactional",
"Message" => "Sending SMS with PHP",
"PhoneNumber" => "+87654321"
);

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

This is not working. I have tested with a lot of different SenderIDs and all messages are received from NOTICE. However, when I send a message from the AWS console, the message is received with the correct SenderID. So I assume my code is wrong.

Upvotes: 2

Views: 1416

Answers (1)

Leonardo
Leonardo

Reputation: 813

I found the solution. Set the args this way. It works!

$args = array(
    'MessageAttributes' => [
        'AWS.SNS.SMS.SenderID' => [
               'DataType' => 'String',
               'StringValue' => 'YourSenderName'
        ]
     ],
    "SMSType" => "Transactional",
    "PhoneNumber" => "+87654321",
    "Message" => "Hello World!"
);

Upvotes: 10

Related Questions