1

i m trying to send a SMS from my trail Twilio account. so please help to get sms response/status

$client = new Client(TWILIO_SID, TWILIO_TOKEN);
    $client->messages->create(
        $mobile,
        array(
            'from' => TWILIO_FROM_NUMBER,
            'body' => $mobile_message,
            //'statusCallback' => "https://requestb.in/v9uqy6v9"
            'statusCallback' => base_url()."sms_status.php"
        )
    );

    //$status = file_get_contents('https://requestb.in/v9uqy6v9');
    $status = file_get_contents(base_url()."sms_status.php");

when i run the above code i got error:

Message: file_get_contents(http://.../sms_status.php): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

while i manually browse the sms_status.php file url than it's not got any error

i also follow this link How to get notified when SMS Status changes from 'Queued' to 'Sent'?

so please help me to resolve above problem and also define what will be format of output like json/text/array.....

Manoj Rana
  • 3,068
  • 1
  • 24
  • 34

1 Answers1

0

Twilio developer evangelist here.

When you set a statusCallback URL for an SMS message that you send, the URL needs to point to an application that can handle an incoming HTTP request.

When the status of the SMS message changes through queued, failed, sent, delivered, or undelivered Twilio will make an HTTP POST request to your URL, sending all the standard request parameters as well as two extra parameters; MessageStatus and ErrorCode. The parameters will be sent as URL encoded form parameters, so you should be able to read them using PHP's $_REQUEST[] syntax.

So, make sure your application can receive HTTP requests at the statusCallback URL and you can log the data out from there however you want to.

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • It would be tough for me to share your code ;) I don't know what you want to do with it. – philnash Sep 12 '17 at 09:28
  • i just want status code and message only, if message is not possible then you can avoid it – Manoj Rana Sep 12 '17 at 10:54
  • 1
    Hello, I can't write your code for you. I don't know what you want to do with the status or the code. What have you tried so far since I answered this? – philnash Sep 12 '17 at 10:56
  • file sms_status.php is use to get message send status how to retrive this status – Manoj Rana Sep 12 '17 at 13:59
  • It is not used to get the message status, when the message status updates, Twilio will send an HTTP request to `sms_status.php`. That is why it needs to be able to receive incoming requests and then do something with the data. – philnash Sep 12 '17 at 14:23
  • ok, your means , i need to handle twilio request and save status in db or any another json file using file sms_status.php and then get response from there not from sms_status.php – Manoj Rana Sep 13 '17 at 06:37
  • Yes! That's exactly it! – philnash Sep 13 '17 at 09:40