Reputation: 5482
I am using Twilio Api to send sms to users, it gives fatal error if user's phone number is invalid. I want to validate the phone number before sending messages.
Currently I am using the following method to validate it:
public function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
);
$session = curl_init($url);
curl_setopt_array($session, $options);
$content = curl_exec($session);
curl_close($session);
return $content;
}
$response = $this->get_web_page("https://credentials:[email protected]/v1/PhoneNumbers/3234433584");
$resArr = array();
$resArr = json_decode($response)
and it works fine.
But I want to validate it using Twilio's inbuilt functionality. I have searched a lot on internet, but nothing helped.
Upvotes: 0
Views: 1909
Reputation: 15476
The documentation is a wonderful resource for questions like that.
The Twilio SDK has a method for that specific feature:
I'll copy and paste directly from the documentation:
<?php
$client = new Services_Twilio('AC123', '123');
$response = $client->account->outgoing_caller_ids->create('+15554441234');
print $response->validation_code;
You can see examples of responses by trying out their online lookup functionality: https://www.twilio.com/lookup
Upvotes: 4