Reputation: 341
I am trying to retrieve the phone number of a user who sends SMS to my Twilio number, but I can't fetch it in my program.
I have tried these:
$message = $client->account->sms_messages->get("$Smssid");
$number = $message->From;
But no matter what I try $number
is still blank. I have tried to get $sid
, sid
, $SMSSid
. Nothing.
What am I doing wrong?
Upvotes: 2
Views: 971
Reputation: 64844
When a user sends you an SMS, we make an HTTP request to your server. This HTTP request contains info about the SMS, such as the From, To, Body, etc.
To retrieve the 'From' value from the HTTP request in PHP, simply do the following:
$from_number = $_REQUEST['From'];
Alternately you can retrieve it from the REST API:
$message = $client->account->sms_messages->get($_REQUEST['SmsSid'])
Although this should be unneccessary as all the data you need should be in the HTTP request.
Upvotes: 1