Ivijan Stefan Stipić
Ivijan Stefan Stipić

Reputation: 6668

Twilio PHP: How to get outgoing SMS message SID

I use Twilio PHP API and try to record SID of outgoing SMS messages. How to get that info?

I don't have problem to send and recive SMS, that work fine but SID from outgoing messages I need to get messages directly from Twilio in another APP where I not save all message data in database.

$twilio = new Services_Twilio('SID','TOKEN');

    $message = $twilio->account->messages->sendMessage( 
        $_POST['From'], // twilio phone number
        $_POST['To'],   // the number we are sending to - Any phone number
        $_POST['Body']  // the sms body
    );

Upvotes: 0

Views: 2020

Answers (2)

shasi kanth
shasi kanth

Reputation: 7094

If you are using Twilio REST API to send messages, then you can fetch the Message SID like below:

$sms_sent = $client->messages->create(
    '+1xxxxxxxxxx',
    array(
        'from' => 'MESSAGING SERVICE SID',
        'body' => "XXXXXX XXXXXX",
        'statusCallback' => "http://myapplication_callback_url"
    )
);

$sms_sent = (array) $sms_sent;
$sms_sid = $sms_sent["\0*\0" . 'properties']['sid'];

Upvotes: 1

Marcos Placona
Marcos Placona

Reputation: 21720

Twilio developer evangelist here.

To get the message SID, all you need to do is read the value of $message->sid;.

So in your code you could do:

echo $message->sid;

If you wanna see all the variables returned by the request, you could do something like:

var_dump($message);

And this will give you information about all the variables returned.

Hope this help you

Upvotes: 2

Related Questions