<?php
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');
session_start();
$iduser=$_SESSION['user_idd'];
$nam=$_SESSION['name'];
include('../include/config.php');

if(isset($_POST['tel']))
{
$tel=addslashes($_POST['tel']);
$msg=addslashes($_POST['msg']);
$sid=addslashes($_POST['sid']);

$msg=$msg.'.\n For enquiry kindly contact: 0728 966 221';

$baseurl = "https://sms.textsms.co.ke/api/services/sendsms/";
$ch = curl_init($baseurl);
$data= array(
"apikey"=>"dd831d08b4bef652dbb8dbafabdab40b",
"response_type"=> "json",
"partnerID"=>"11288",
"message"=>$msg,
"shortcode"=>"BISHOPKAIRO",
"service_id"=>0,
"mobile"=>$tel,
);

$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-Type: application/json','h_api_key:dd831d08b4bef652dbb8dbafabdab40b'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_encode(curl_exec($ch));

$sql=mysqli_query($con,"INSERT INTO parentsmessages(pid,Phone,Msg,Dat,User,UserName) VALUES('$sid','$tel','$msg','$timenow','$iduser','$nam')");
if($sql)
{
  echo 'success';  
}

echo $result;
curl_close($ch);
}
?>
