user1581579
user1581579

Reputation: 341

Get phone number of SMS sender, using Twilio

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

Answers (1)

Kevin Burke
Kevin Burke

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

Related Questions