Sample Bulk PHP – CURL

Image Description
<?php
header('Access-Control-Allow-Origin:*'); 
//API Url
$url = 'sms.textware.lk:5000/sms/send_sms.php';

//Initiate cURL.
$ch = curl_init($url);

//The JSON data.
$jsonData = array(
   
   
   'action' => "bulk_put",
   'user' => "xxxx",
   'password' => "xxxxx",
   'ea'=>"xxxxx",
   'campaign'=>"bulk",  
    'records'=>[[
    'src'=>"xxxx",
    'dst'=>"94775553892",
    'msg'=>"Test Message",
    'dr'=>"1"
    ]]

);

//Encode the array into JSON.

try {
    $jsonDataEncoded = json_encode($jsonData);
   
      }
catch(Exception $e) {
    echo 'Message:1 ' .$e->getMessage();
  }

try {
    curl_setopt($ch, CURLOPT_POST, 1);
    //Tell cURL that we want to send a POST request.
    
   }
 catch(Exception $e) {
     echo 'Message:2 ' .$e->getMessage();
   }

try{
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

}catch(Exception $e){
    echo 'Message:3 ' .$e->getMessage();
}

try{

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

}catch(Exception $e){
    echo 'Message:4 ' .$e->getMessage();
}

echo " Input Json:<br>";
echo $jsonDataEncoded;
echo "<br>";
echo "<br>Response:<br>";
//Execute the request
$result = curl_exec($ch);
?>

Was this article helpful to you?

Yes No

Related Articles