SenderID using Amazon PHP SDK Web Services

I am trying to send SMS through my PHP website using the AWS SDK. I am using the code from Sending SMS using Amazon AWS PHP services .

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" => "Transational",
"Message" => "Sending SMS with PHP",
"PhoneNumber" => "+12345678"
);

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

This does not work. I checked many different SenderIDs and all messages were received from NOTICE. However, when I send a message from the AWS console, the message is received with the correct sender ID. Therefore, I assume that my code is incorrect.

+1
source share
1 answer

I have found a solution. Set the arguments this way. He works!

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

Source: https://habr.com/ru/post/1680157/


All Articles