Twilio cURL calling a phone Twilio cURL calling a phone curl curl

Twilio cURL calling a phone


Twilio Developer Evangelist here.

Your code is really close. Just two small changes should resolve your issue. First you need to remove this line: curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: 7' ));

This was truncating your POST data which resulted in the "From" information not being sent.

Second, you don't need to urlencode the $CallURL because curl handles this for us.

Once you make both of these changes your code should look like this and run without an 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'  , // My Number   'Url' => $CallURL,   'Method'=>'GET' ,   'FallbackMethod'=>'GET',   'StatusCallbackMethod'=>'GET',   'Record'=>'false'  );  $post = http_build_query($fields);  $curl = curl_init($url);  // Set some options - we are passing in a useragent too 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 this gets your issues resolved.