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.
<?php
header('Content-Type: text/html; charset=UTF-8');
// $message = "नमस्कार सुभोदय";
// $message = "à¤?à¤? à¤?à¥? मà¥à¤?à¥à¤¯ समाà¤?ार";
$message="ఇది టెస్ట్ మెసేజ్";
$finalmessage = "";
$sss = "";
for($i=0;$i<mb_strlen($message,"UTF-8");$i++) {
$sss=mb_substr($message,$i,1,"utf-8");
$a=0;
$abc="&#" .ordutf8($sss,$a).";";
$finalmessage.=$abc;
}
echo $finalmessage;
function ordutf8($string, &$offset){
$code=ord(substr($string, $offset,1));
if ($code >= 128)
{ //otherwise 0xxxxxxx
if ($code < 224) $bytesnumber = 2; //110xxxxx
else if ($code < 240) $bytesnumber = 3; //1110xxxx
else if ($code < 248) $bytesnumber = 4; //11110xxx
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx
$codetemp = $codetemp*64 + $code2;
}
$code = $codetemp;
}
return $code;
}
$data = array(
"username" => "XXXXXX", // type your assigned username
"password" => "XXXXXXX", //type your password
"senderid" =>"XXXXXX", //type your senderID
"smsservicetype" => "unicodemsg",
"bulkmobno" => "97305XXXXX,762067XXXX",//*Note*:for single number enter one number
"content" => $finalmessage //type the message.
);
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . urlencode($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_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-length:" . strlen($fields) ));
curl_setopt($post, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($post);
curl_close($post);
}
post_to_url("http://msdgweb.mgov.gov.in/esms/sendsmsrequest", $data);
?>
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.
<?php
header('Content-Type: text/html; charset=UTF-8');
// $message = "नमस्कार सुभोदय";
// $message = "à¤?à¤? à¤?à¥? मà¥à¤?à¥à¤¯ समाà¤?ार";
$message="ఇది టెస్ట్ మెసేజ్";
$finalmessage = "";
$sss = "";
for($i=0;$i<mb_strlen($message,"UTF-8");$i++) {
$sss=mb_substr($message,$i,1,"utf-8");
$a=0;
$abc="&#" .ordutf8($sss,$a).";";
$finalmessage.=$abc;
}
echo $finalmessage;
function ordutf8($string, &$offset){
$code=ord(substr($string, $offset,1));
if ($code >= 128)
{ //otherwise 0xxxxxxx
if ($code < 224) $bytesnumber = 2; //110xxxxx
else if ($code < 240) $bytesnumber = 3; //1110xxxx
else if ($code < 248) $bytesnumber = 4; //11110xxx
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx
$codetemp = $codetemp*64 + $code2;
}
$code = $codetemp;
}
return $code;
}
$data = array(
"username" => "XXXXXX", // type your assigned username
"password" => "XXXXXXX", //type your password
"senderid" =>"XXXXXX", //type your senderID
"smsservicetype" => "unicodemsg",
"bulkmobno" => "97305XXXXX,762067XXXX",//*Note*:for single number enter one number
"content" => $finalmessage //type the message.
);
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . urlencode($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_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
curl_setopt($post, CURLOPT_HTTPHEADER, array("Content-length:" . strlen($fields) ));
curl_setopt($post, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($post);
curl_close($post);
}
post_to_url("http://msdgweb.mgov.gov.in/esms/sendsmsrequest", $data);
?>