简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM