XML API for Sending BULK Numbers
Our function which sends bulk Numbers.
Once this function is run, it will send 1000 SMS at a time.
We call this function in a loop(which loops for 10 times) that is in a program, 10000 SMS should be sent.
function send_subcampaign(){
global $uid,$cmpid,$numbers,$scmpid,$scheduledatetime;
global $user,$password,$api_id;
global $db_host,$db_name,$db_user,$db_password; //include global variables
//get message
$textanddate=get_message();
$text=$textanddate[0];
echo "message: ".$text."<br />\r\n";
$numbersarray=explode(",",$numbers); //stores numbers as array
$message_ids=array(); //stores message ids
/*XML API by Aditya*/
$numbers_xml_string=""; //stores XML string of numbers and message
foreach($numbersarray as $mob){
$numbers_xml_string.="<Message><To>".$mob."</To><Text>".$text."</Text></Message>";
}
//XML string to be encoded
$xmlstring="<SmsQueue><Account><User>".$user."</User><Password>".$password."</Password></Account><MessageData><SenderId>".$api_id."</SenderId><Gwid>1</Gwid><DataCoding>0</DataCoding></MessageData><Messages>".$numbers_xml_string."</Messages></SmsQueue>";
$xmlstring=urlencode($xmlstring);//encode the string
//prepare URL
$url="http://login.smsgatewayhub.com/xmlapi/pushsms.aspx?data=".$xmlstring;
// create a new cURL resource
$ch = curl_init();
//set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$response=curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
//explode response as an array to insert into database
$responsearray=explode("Thread",$response); //response will contain message ids separated by space (' ')
$xml =new SimpleXMLElement($responsearray[0]);
$count=0;
foreach ($xml->children() as $MessageIds){
$message_ids[$count]=(string)$MessageIds[0];
//echo "Message Id: ".$message_ids[$count]."<br />\r\n";
$count++;
}
//connect to the database
$con=mysqli_connect($db_host,$db_user,$db_password,$db_name);
foreach($message_ids as $msgid){
$result = mysqli_query($con,"insert into smsmessagereport(cmpid,uid,messageid) values(".$cmpid.",".$uid.",'".$msgid."')");
}
//close connection
mysqli_close($con);
/*End XML API by Aditya*/
}
For API Please signup at : www.smsgatewayhub.com
Please note that some of the above code has been supplied to SMSGATEWAYHUB by clients. As such, accuracy is not guaranteed by SMSGATEWAYHUB.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article