<?php
error_reporting(E_ALL);
//phpinfo();
$userName = "923475026795";
$Password= "686765A465768779aa";
$number = "923404599448";
$message = "this is test message";
$mask = "Education";
$planetbeyondApiUrl="https://telenorcsms.com.pk:27677/corporate_sms2/api/auth.jsp?msisdn=".$userName."&password=".$Password.""; 
$resp = file_get_contents($planetbeyondApiUrl);
var_dump($resp);die;
$sessionKey=getSessionId($userName,$Password,$planetbeyondApiUrl); 
//print($sessionKey);
//exit;

$planetbeyondApiSendSmsUrl="https://telenorcsms.com.pk:27677/corporate_sms2/api/sendsms.jsp?session_id=".$sessionKey."&to=".$number."&text=".$message.""; 
$url=str_replace("#message_text#",urlencode($message),$planetbeyondApiSendSmsUrl); 
$url=str_replace("#to_number_csv#",$number,$url); 
$url=str_replace("#from_number#",$userName,$url); 
$urlWithSessionKey=str_replace("#session_id#",$sessionKey,$url); 
if($mask!=null) 
{ 
 $urlWithSessionKey = $urlWithSessionKey . "&mask=" . $mask; 
} 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlWithSessionKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//var_dump($result);
//var_dump(curl_getinfo($ch));
// also get the error and response code
$errors = curl_error($ch);
if(!$result){
    //die("Connection Failure");
    $result = $errors ; 
    
}
   curl_close($ch);
function getSessionId($userName,$Password,$planetbeyondApiUrl) 
{ 
error_reporting(E_ALL);
 $url=str_replace("#username#",$userName,$planetbeyondApiUrl); 
 $url=str_replace("#password#",$Password,$url); 
 
 $response = file_get_contents($url);
 var_dump($response);die;
 //echo $url ; echo '<br>';
 //echo 'abc'.$response  ; die ;
 $response=@simplexml_load_string($response) or die("Error: Cannot create object");
 //print_r($response);

    if($response && substr($response->response,0,5)!=="Error") 
    { 
        return $response->data; 
    } 
 return -1; 
} 


?>


