SenderID using Amazon Web Services PHP SDK
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!"
);
How to set the from number on AWS SNS (Using PHP v3 SDK)
So the solutions to this, after much looking around and rubber ducking the problem while typing into the text box above, is to use a couple of different answers together. The Stack Overflow thread mentioned in prior research about setting the SenderID was very helpful to atleast getting the raw information into the AWS SDK.
$params = array(
'credentials' => array(
'key' => 'iam_key',
'secret' => 'iam_secret',
),
'region' => 'ap-south-1', // < your aws from SNS Topic region
'version' => 'latest',
'http' => ['verify'=>false]
);
$sns = \Aws\Sns\SnsClient::factory($params);
$msgattributes = [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => 'Klassroom',
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Transactional',
]
];
$payload = array(
'Message' => "HK test",
"PhoneNumber" => "1234567890",
'MessageAttributes' => $msgattributes
);
$result = $sns->publish($payload);
If you scroll into the SMS Publish To Phone documentation, you'll see the string used above AWS.SNS.SMS.SenderID
and the next item down is ... AWS.MM.SMS.OriginationNumber
... So maybe that will work?
IT'S WORKING! IT'S WORKING!
require 'vendor/autoload.php';
use Aws\Sns\SnsClient;
use Aws\Exception\AwsException;
$SnSclient = new SnsClient([
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-03-31'
]);
$msgAttributes = [
'AWS.MM.SMS.OriginationNumber' => [
'DataType' => 'String',
'StringValue' => '+1XXXYYYZZZZ',
]
];
$message = 'This message is sent from a Amazon SNS code sample.';
$phone = '+1AAALLL####';
try {
$result = $SnSclient->publish([
'Message' => $message,
'PhoneNumber' => $phone,
'MessageAttributes' => $msgAttributes
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
Note: Obviously, +1XXXYYYZZZZ
is a number from my already established long code list, and just like before +1AAALLL####
is my phone number or the phone number of the person I want to send the text message to.
SenderID' issues sending SMS on Amazon SNS (Official PHP SDK)
I have found the answer.
The search system didn't materialise this originally, but finally, I have found it.
QUOTE FROM: https://stackoverflow.com/a/43748448/7586984
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!"
);
Related Topics
Pass PHP Variable to Bootstrap Modal
Get All the Images from a Folder in PHP
Avoid Add to Cart for Specific Product Categories If User Is Unlogged in Woocommerce
Checking If an Instance's Class Implements an Interface
Problem with Adding Root Path Using PHP Domdocument
How to Create a Logfile in PHP
Update Xampp from Maria Db 10.1 to 10.2
Why Can't I Overload Constructors in PHP
Wordwrap/Cut Text in HTML String
How to Post Soap Request from PHP
Windows 7 PHP + Symfony2 Terribly Slow
Pdo Looping Through and Printing Fetchall
Creating New Laravel Project via Composer Fails with Error Class Arrayloader Not Found
What Are the Risks of PHP Sessions
Working with Two Entity Managers in the Same Bundle in Symfony2