I have successfully attempted sending SMS to a phone number using Twilio REST API in PHP. Currently I am using a trial account. I can see logs on Twilio console too. When I attempt to send SMS to an invalid number, Twilio REST API gives me error:
Error 21614 - 'To' number is not a valid mobile number.
I can't view this error in Twilio Programmable SMS logs or Debugger Logs. So when I submit a bulk of numbers to Twilio, how can I find at the end, that which numbers failed to receive the SMSs because of error 21614, on Twilio Console? Currenty, I do not want to log it through my PHP code.
Thank you.
EDIT
If you want to go through the console you can see this link as you do not want to manage it via php
For managing at your end with StatusCallback
You need to use optional parameter StatusCallback and specify a callback URL where Twilio will POST each time your message status changes to one of the following:
queued,
failed,
sent,
delivered,
or undelivered.
Twilio will POST the MessageSid along with the other standard request parameters as well as MessageStatus and ErrorCode. If this parameter passed in addition to a MessagingServiceSid, Twilio will override the Status Callback URL of the Messaging Service. URLs must contain a valid hostname (underscores are not allowed). You can learn more about it here
you can add your php code there to keep track of every new message and keep updating the logs for that message.
Hope that helps
Related
I am using PHP from Twilio API, to make calls and sms from my php code, the sms is working, but when the calls it shows an error, please! I need help
I bought a number from twilio and upgarde, but it still shows the same error
Error: [HTTP 400] Unable to create record: The source phone number provided, +151**********, is not yet verified for your account. You may only make calls from phone numbers that you've verified or purchased from Twilio.
Twilio developer evangelist here.
When making calls you can set the number that you are calling from as either a Twilio number or a number that you have verified is your own. The error message is saying that neither of these conditions have been met.
If you are trying to make a call with a Twilio number that you have bought, then I would double check the number in your code to make sure it matches your Twilio number.
If you are trying to call from your own phone number, then make sure the number appears in your verified numbers list in your Twilio console. If it doesn't then you will need to verify it from that page first.
Let me know if that helps at all.
for me, it was because I live in Algeria and Algeria is disabled by default on my Geo permission page. if the above solution didn't work you should check your Geo permission Page in the Verify tab and look for the country you're trying to send messages to and see if it's enabled
i am using Twilio API to send and receive sms from the customers.
Every time i send the sms to my customers, i store the feilds like to, body in to my database.
I have implemented the API for send message that works fine and am simply saving the fields in to my database.
My Problem
When i receive SMS from my customers to my twilio number. i want to get the fields like from number and the body and save to my databse.
i looked that the documentation here
https://www.twilio.com/docs/api/twiml
https://www.twilio.com/blog/2012/04/get-started-with-twilio-sms-receiving-incoming-sms-quickstart.html
But this only shows how to send a response to customer when a message is received.
I want to save the received sms in to my database.
Can someone help me top get the from number and the message body when a SMS is received. tnx..
Twilio evangelist here.
Twilio passes parameters in its HTTP request as form-encoded values, so you just need to use the REQUEST object to grab them:
$from = $_REQUEST['From']
The SMS Quickstart for PHP has a more detailed example.
Hope hat helps.
The documentation for Twilio SMS responses is here:
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Here is a relevant quote:
When Twilio receives a message for one of your Twilio numbers it makes
a synchronous HTTP request to the message URL configured for that
number, and expects to receive TwiML in response. Twilio sends the
following parameters with its request as POST parameters or URL query
parameters, depending on which HTTP method you've configured.
You should simply have the data fields inside of PHP's $_REQUEST[] variable.
$_REQUEST['MessageSid'] - A 34 character unique identifier for the message. May be used to later retrieve this message from the REST API.
$_REQUEST['SmsSid'] - Same value as MessageSid. Deprecated and included for backward compatibility.
$_REQUEST['AccountSid'] - The 34 character id of the Account this message is associated with.
$_REQUEST['From'] - The phone number that sent this message.
$_REQUEST['To'] - The phone number of the recipient.
$_REQUEST['Body'] - The text body of the message. Up to 1600 characters long.
$_REQUEST['NumMedia'] - The number of media items associated with your message
Here is an example query you might use with a MySQL database. You should also be sending back a proper TWIXML response to Twilio and scrub the received data before running a query like this.
$sql = "INSERT INTO messages (sid, from, body)
VALUES (
'".$_REQUEST['MessageSid']."',
'".$_REQUEST['From']."',
'".$_REQUEST['Body']."'
)";
What I am trying to accomplish is quite simple. I want to store all received SMS messages from a Twilio number in a database. Upon checking Twilio's documentation, their TwiML word should be able to do this, but no attribute relates to this:
https://www.twilio.com/docs/api/twiml/sms
Twilio developer evangelist here.
When your Twilio number gets sent an SMS, your application receives a webhook at the URL you supply in the settings for the number. For each messages, the webhook sends a number of parameters telling you about the message. The documentation for that can be found here: https://www.twilio.com/docs/api/twiml/sms/twilio_request.
You might want to take a look at our PHP Quickstart tutorial which will give you a good idea of how to get the details from the request. You will then just have to pick which attributes you want to store in your database.
Let me know if this helps.
I use twilio API to send SMS from my php application. When the 'to' number is malformed (invalid area code, invalid digits number etc) twilio works fine, giving me an exception.
My problem is when I try to send to a number that is in good format, however it doesn't exist. It show it as 'sent' and no exception is given. I also tried the callback option:
array('StatusCallback' => 'http://uncurler.heroku.com/v1/<some code >').
Even when i view the report here it shows as 'sent'.
Is there a way to actually know if the message was delivered? Or more importantly if it was NOT delivered? If not, is it possible from some other API?
Twilio evangelist here.
So currently the Status value does not reflect anything beyond our ability to deliver the message to the carrier. It does not reflect any information about whether or not the carrier was able to deliver the message or not.
If the carrier accepts the message from us, we mark the message as Sent.
Hope that helps.
I have created a free account in twilio for sending SMS through my website. After my registration I got a twilio number like XXX-XXX-XXXX. I am able to send message to mobile numbers but I don't know how to use this twilio number for receiving SMS. Please help me out on this.
Twilio evangelist here.
The way Twilio notifies you of both incoming SMS message and incoming voice phone calls is by using something called a webhook. This is basically an HTTP request that Twilio makes to a URL that you tell us about. Normally this URL is a web app that you've created and published to a public website.
http://en.wikipedia.org/wiki/Webhook
In your Twilio dashboard, click on the Numbers tab and you will see your trial number.
https://www.twilio.com/user/account/phone-numbers/incoming
Click the phone number and you will see two input fields, one for a Voice URL and one for a SMS url. Just put your URL's there and click the save button.
Now if you send a text message to your number, Twilio will make an HTTP request to the URL you've told us about. You can think of this like a standard Form submit. Twilio will send along parameters like the number the SMS is coming from and the body of the message. The full list of parameters we send to the SMS url is here:
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Your app can grab those parameters and use them however it wants. Your app can also return TwiML instructions to us that tell us to respond to the SMS.
https://www.twilio.com/docs/api/twiml/sms/your_response
You might want to check out our quickstarts for examples of how to receive a text message and and howtos for lots more examples of both sending and receiving SMS messages.
https://www.twilio.com/docs/quickstart/php/sms/hello-monkey
https://www.twilio.com/docs/howto
Hope that helps.
Devin