SMS sending URL Not working With curl


I am using below code to send SMS by php curl. From browser when I am running $apiURL it works fine for me. But using below code of curl it’s not working. OI gtting O/P as string(0) "". Am I doing something wrong,please help me.

$conturyCode = "91";
$client_mobile = "96******18";
$new_centername = "Apple Hospital";
$address = "Lal Darvaja,ringroad,surat(394220)";
$center_mobile = "86******91";
$apiURL = "".$conturyCode.$client_mobile."&source=ABC&message=Scheduled at ".$new_centername." and ".$address." and ".$center_mobile;

//  Initiate curl
$ch = curl_init();
//Set User client
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");

curl_setopt($ch, CURLOPT_VERBOSE, true);
// Set The Response Format to Json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Set Auto referer
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $apiURL);
// Execute
$result = curl_exec($ch);

// Check if any error occurred
    echo 'Curl error: ' . curl_error($ch);

// Closing



Try the below code:

$message = urlencode("Scheduled at ".$new_centername." and ".$address." and ".$center_mobile);
$apiURL = "".$conturyCode.$client_mobile."&source=ABC&message=".$message;

The message that you are passing needs to be url encoded.

Answered By – Swapnil Punekar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published