Thursday, 12 February 2015

send sms through php using cdac service

Before using the sms service we must first install PHP5_CURL as we are using curl function

Command to install is : sudo apt-get install php5-curl

then after restart the apache server:
              sudo   /etc/init.d/apache2 restart

If the above step not done we will receive a error " CALL TO UNDEFINED FUNCTION CURL_INIT"

and, if it is executed in browser you may receive 500 - server error.

So, before proceeding please install the above step.


if((strlen($this->mobile) > 0) && ($this->sec_year!=null) && ($this->sec_fno!=null)){
$mnum = "0".$this->mobile;
$msecno = $this->sec_fno;
$msecyr = $this->sec_year;
if($this->clo_yn<>'Y'){
$data = array(
  "username" => "Username",
"password" => "Password",
"senderid" =>"Service Name",    
"smsservicetype" =>"singlemsg",  // bulkmsg for bulk messages
"mobileno" =>"$mnum",
// "bulkmobno" => "09999999999,07777777777,08888888888,09879879879",
"content"  => "your inward entry no. $this->inw_no with fileno. $msecno/$msecyr is Moved to   $sname"
);
}else{
$data = array(
  "username" => "Username",      
"password" => "Password",  
"senderid" =>"ServiceName",      
"smsservicetype" =>"singlemsg",
"mobileno" =>"$mnum",      
"content"  => "Your Abids Collectorate Inward no. $this->inw_no with fileno. $msecno/$msecyr is CLOSED"
);
}
   //    return post_to_url("http://msdgweb.mgov.gov.in/esms/sendsmsrequest", $data);
$url="http://msdgweb.mgov.gov.in/esms/sendsmsrequest";

$fields = '';
       foreach($data as $key => $value) {
          $fields .= $key . '=' . $value . '&';
       }
       rtrim($fields, '&');
$post = curl_init();

       curl_setopt($post, CURLOPT_URL, $url);
       curl_setopt($post, CURLOPT_POST, count($data));
       curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
       curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
       // echo "response from website  ";
       $result = curl_exec($post);

       curl_close($post);

No comments:

Post a Comment