php - Twilio cURL calling a phone -


based on documentation of twilio , curl have php curl routine:

function twilio($mobile,$msg,$twocode){ $url = 'https://api.twilio.com/2010-04-01/accounts/'.twilio_account_sid.'/calls.json'; $callurl = 'http://myweb.com/code/say/'.$twocode; $auth = twilio_account_sid.":".twilio_auth_token; $fields = array(  'to' =>  $mobile  ,  'from' => '+16262471234'  , // number  'url' => urlencode( $callurl ) ,  'method'=>'get' ,  'fallbackmethod'=>'get',  'statuscallbackmethod'=>'get',  'record'=>'false' ); $post = http_build_query($fields); $curl = curl_init($url); // set options - passing in useragent here curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_httpauth, curlauth_basic); curl_setopt($curl, curlopt_ssl_verifypeer, false); curl_setopt($curl, curlopt_useragent , 'mozilla 5.0'); curl_setopt($curl, curlopt_postfields, $post); curl_setopt($curl, curlopt_httpheader, array('content-length: 7' )); curl_setopt($curl, curlopt_userpwd, $auth); curl_setopt($curl, curlopt_verbose , true); $resp = curl_exec($curl); curl_close($curl); } 

it gives me error:

{"code": 21213, "message": "no 'from' number specified", "more_info": "https://www.twilio.com/docs/errors/21213", "status": 400} 

i tried options, can help?

i edited , added "+" "from" number. still error remains same.

thanks in advance!

twilio developer evangelist here.

your code close. 2 small changes should resolve issue. first need remove line: curl_setopt($curl, curlopt_httpheader, array('content-length: 7' ));

this truncating post data resulted in "from" information not being sent.

second, don't need urlencode $callurl because curl handles us.

once make both of these changes code should , run without error:

function twilio($mobile,$msg,$twocode){   $url = 'https://api.twilio.com/2010-04-01/accounts/'. twilio_account_sid.'/calls.json';   $callurl = 'http://myweb.com/code/say/'.$twocode;   $auth = twilio_account_sid .":". twilio_auth_token;   $fields = array(    'to' =>  $mobile  ,     'from' => '+16262471234'  , // number    'url' => $callurl,    'method'=>'get' ,    'fallbackmethod'=>'get',    'statuscallbackmethod'=>'get',    'record'=>'false'   );   $post = http_build_query($fields);   $curl = curl_init($url);   // set options - passing in useragent here   curl_setopt($curl, curlopt_post, true);   curl_setopt($curl, curlopt_returntransfer, true);   curl_setopt($curl, curlopt_httpauth, curlauth_basic);   curl_setopt($curl, curlopt_ssl_verifypeer, false);   curl_setopt($curl, curlopt_useragent , 'mozilla 5.0');   curl_setopt($curl, curlopt_postfields, $post);   curl_setopt($curl, curlopt_userpwd, $auth);   curl_setopt($curl, curlopt_verbose , true);    $resp = curl_exec($curl);    curl_close($curl); } 

let me know if gets issues resolved.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -