简体   繁体   中英

How to send sms in hindi using php

i have successfully integrated the bulk sms gateway and its sending the message too. But,now i am trying to send the sms in hindi. When i put hindi message like

$message = 'बधाई हो! मेरी वेबसाइट में आपका स्वागत है, अब आप हमारे सदस्य हैं। आपका url है '.$url.' ';

It shows me ?????????????? ???????? ????? like this.

Here is my php code:

<?php
include 'config.php';
if(isset($_POST['save'])){
    $user = "xxxxxxxxxxxx";
    $password = "xxxxxxxxxxxxx";
    $senderid = "xxxxxxxxxxxxxx";
    $checkbox = $_POST['check'];
    for($i=0;$i<count($checkbox);$i++){
    $del_id = $checkbox[$i]; 
    mysqli_query($conn,"UPDATE inventory_details SET status='0' WHERE id='".$del_id."'");
}
}

$smsurl = "http://kit19.com/ComposeSMS.aspx?";

function httpRequest($url){
    $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
    preg_match($pattern,$url,$args);
    $in = "";
    $fp = fsockopen($args[1],80, $errno, $errstr, 30);
    if (!$fp) {
       return("$errstr ($errno)");
    } else {
        $args[3] = "C".$args[3];
        $out = "GET /$args[3] HTTP/1.1\r\n";
        $out .= "Host: $args[1]:$args[2]\r\n";
        $out .= "User-agent: Website\r\n";
        $out .= "Accept: */*\r\n";
        $out .= "Connection: Close\r\n\r\n";

        fwrite($fp, $out);
        while (!feof($fp)) {
           $in.=fgets($fp, 128);
        }
    }
    fclose($fp);
    return($in);
}

function SMSSend($phone, $msg, $debug=false){
      global $user,$password,$senderid,$smsurl;

      $url = 'username='.$user;
      $url.= '&password='.$password;
      $url.= '&sender='.$senderid;
      $url.= '&to='.urlencode($phone);
      $url.= '&message='.urlencode($msg);
      $url.= '&priority=1';
      $url.= '&dnd=1';
      $url.= '&unicode=0';


      $urltouse =  $smsurl.$url;
      if ($debug) { echo ""; }

      $response = httpRequest($urltouse);
      if ($debug) {

        str_replace(array("<",">"),array("&lt;","&gt;"),$response).
           "</pre><br>"; }

      return($response);
}

$checkbox = $_POST['check'];
    for($i=0;$i<count($checkbox);$i++){
    $del_id = $checkbox[$i]; 
    $PrimaryMobile = mysqli_query($conn,"SELECT * FROM inventory_details WHERE id='".$del_id."'");
    while($row = mysqli_fetch_array($PrimaryMobile)) {
        $PrimaryMobile_no = $row['PrimaryMobile_no'];
        $firm_name = $row['firm_name'];

        $firm_name = urldecode($firm_name);  
        $firm_name = str_replace(' ', '-', $firm_name); 
        $firm_name = str_replace('&', '-', $firm_name); 
        $firm_name = str_replace('(', '-', $firm_name); 
        $firm_name = str_replace(')', '-', $firm_name); 

                        # are you missing a / here ???
        $url = 'http://www.example.com/' . urlencode($del_id) . '-' . urlencode($firm_name);

        $message = 'बधाई हो! मेरी वेबसाइट में आपका स्वागत है, अब आप हमारे सदस्य हैं। आपका url है '.$url.' ';
    }

$debug = true;
SMSSend($PrimaryMobile_no,$message,$debug);

}
?>

I have tried the script :

public function utf8_to_unicode($str) {
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen($str); $i++) {
    $thisValue = ord($str[$i]);
    if ($thisValue < 128) {
        $number = dechex($thisValue);
        $unicode[] = (strlen($number) == 1) ? '%u000' . $number : "%u00" . $number;
    } else {
        if (count($values) == 0)
            $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
        $values[] = $thisValue;
        if (count($values) == $lookingFor) {
            $number = ( $lookingFor == 3 ) ?
                    ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ) :
                    ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64
                    );
            $number = dechex($number);
            $unicode[] =
                    (strlen($number) == 3) ? "%u0" . $number : "%u" . $number;
            $values = array();
            $lookingFor = 1;
        } // if
    } // if
}
return implode("", $unicode);
}

but its not working. Please help me out. Thanks

First, you need to know, that not all Bulk SMS provider support or allow Unicode Message. There are different encoding for each SMS format. So far I found SMS.to allow Unicode SMS sending, which mean you can send SMS in Hindi or any other regional language.

转码选项

They count 70 Unicode characters as 1 SMS, which is far better from most of the Bulk SMS providers, which will allow only 30 characters in 1 SMS. They also offer REST API: https://sms.to/api-docs so it's easy to integrate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM