0

hi there i am trying to send bulk sms using bulk sms api in php i am a newbie so i dnt have much idea abt this bt i went through google and found some scripts but wen i try to send the sms it shows the error "NO DATA RECIEVED" can anyone help me here is m script

<?php

    if (isset($_POST["submit"])) {


         require("includes/config.php");
         require("includes/dbconnect.php");
         require("includes/functions.php");

        $tourdb = DBSUFFIX . $_SESSION["cono"] . "_" . $_SESSION["tourname"];
        mysql_select_db($tourdb);

        $message = substr($_POST["sms"], 0, 160);

        $cond = "";
        if (!empty($_POST["district"])) {
            $district = trim($_POST["district"]);
            $cond .= "AND `district` = '$district'";
        }

        if (!empty($_POST["state"])) {
            $state = trim($_POST["state"]);
            $cond .= "AND `state` = '$state'";
        }

        if (!empty($_POST["for"])) {
            $for = trim($_POST["for"]);
            $cond .= "AND `visitingfor` = '$for'";
        }

        $ccond = "";
        if (!empty($_POST["Airline"])) {
            $air = trim($_POST["Airline"]);
            $ccond .= "AND `airline_code` = '$air'";
        }

        if (!empty($_POST["bjdate"])) {
            $date1 = trim($_POST["bjdate"]);
            $ccond .= "AND `dept_date` = '$date1'";
        }

        if (!empty($_POST["jbdate"])) {
            $date2 = trim($_POST["jbdate"]);
            $ccond .= "AND `dept_date` = '$date2'";
        }

        if (!empty($_POST["siscono"])) {
            $siscono = trim($_POST["siscono"]);
            $cond .= "AND `company` = '$siscono'";
        }

        if (!empty($_POST["batch"])) {
            $batch = $_POST["batch"];
            $ccond .= " AND `batchno` = '$batch' ";
        }

        $hajicond = "";
        if (!empty($_POST["fromhaji"]) && !empty($_POST["tohaji"])) {
            $fromhaji = $_POST["fromhaji"];
            $tohaji = $_POST["tohaji"];
            $hajicond = " AND `hajino` BETWEEN '$fromhaji' AND '$tohaji'";
        }

        $paxcond = "";
        if (!empty($_POST["frompax"]) && !empty($_POST["topax"])) {
            $frompax = $_POST["frompax"];
            $topax = $_POST["topax"];
            $paxcond = " AND `paxid` BETWEEN '$frompax' AND '$topax'";
        }

        $msg = $_POST["sms"];



        $ctr = 0;
        $query = mysql_query("SELECT RIGHT(`mobile`,10) as `mobile`  FROM `pax` WHERE LENGTH(`mobile`) >= 10 AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE paxno IS NOT NULL $ccond) $cond $hajicond $paxcond ") or die(mysql_error());
            while ($pax = mysql_fetch_array($query)){
                $ctr++;
                $to.= "$pax[mobile],";
             }  

    $to.= "8652372200";

    $user = "****";
    $password = "t*****"; 
    $mobilenumbers = "$to";
    $message = "$msg";
    $senderid = "****";
    $url = "http://tran.mobilogi.com/api/httpapi.php";
    $message = urlencode($message);
    $ch = curl_init();
    echo "$user";
    if (!$ch) {
        die("Couldn't initialize a cURL handle");
    }
    $ret = curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$user&password=$password&to=$mobilenumbers&sender=$senderid&message=$message");

    $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);



    $curlresponse = curl_exec($ch);
    if (curl_errno($ch))
        echo 'curl error : ' . curl_error($ch);

    if (empty($ret)) {

        die(curl_error($ch));
        curl_close($ch); 
    } else {
        $info = curl_getinfo($ch);
        curl_close($ch);

        echo $curlresponse;
        }



    }
    ?>

2 Answers 2

1

There is no function in PHP or javascript that can send sms directly. SMS are basically based on Short Message Peer-to-Peer (SMPP) protocol so there is no way you can directly send sms programmatically. Yes you could use smsgateway or an existing api where you can make a http request from php. There are lot of sms service providers like VAS providers and there are lot of free and open source smsgateway like kannel which you can use to send/recieve sms or if you could configure your own gateway as well.

You need a 3rd party to send your messages through and you will also have to pay something for sending them. I haven't tried it myself but this tutorial on Sending SMS thru HTTP seems like a nice way to go. It'll enable you to

Use PHP and the HTTP protocol to send text-messages from your website through an SMS gateway.
2
  • i know that and i am using sms gateaway as well
    – kumail
    Mar 2, 2013 at 7:26
  • Then read 3rd Party API how to do it right way or ask company
    – Vineet1982
    Mar 2, 2013 at 7:34
0

You can use our API. Since you're already using http request via curl library, it will be no problem to use one of two options we provide for bulk sms requests (see this answer for example):

Full form

When you're describing each message you want to send and everything missed will be taken from a template:

POST /sms/v1/{subAccountId}/many

{
  "clientBatchId": "Demo#1001",
  "messages": [
    {
      "destination": "6598760001"
    },
    {
      "destination": "659876002",
      "source": "SenderId2",
      "clientMessageId": "id_100001"
    },
    {
      "destination": "509750003",
      "country": "FR",
      "source": "SenderId3",
      "text": "Custom message: สวัสดี",
      "encoding": "UCS2",
      "clientMessageId": "id_100002"
    }
  ],
  "template": {
    "source": "DefaultSenderId",
    "text": "Default message for all phone numbers"
  }
}

Compact form

When you're enumerating only phone numbers and everything else comes from a template:

POST /sms/v1/{subAccountId}/many/compact

{
  "destinations": [
    "6598760000",
    "+659870001",
    "tel+659870002",
    "+33(509)758-000"
  ],
  "template": {
    "source": "BRAND",
    "text": "Your message for all clients"
  }
}

Check out this tutorial for a more smooth dive into API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.