簡體   English   中英

如何使用PHP中的SMS API從MySQL數據庫將批量SMS發送到手機號碼

[英]how to send bulk sms to mobile numbers from mysql database using sms api in php

您好,我正在嘗試使用PHP中的批量短信API發送批量短信,所以我是新手,所以我對這個BT不太了解,我通過Google並找到了一些腳本,但是我嘗試發送短信,它顯示了錯誤“沒有數據已收到”,有人可以在這里幫我嗎?

<?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;
        }



    }
    ?>

PHP或javascript中沒有可以直接發送短信的功能。 SMS基本上基於短消息對等(SMPP)協議,因此您無法以編程方式直接發送短信。 是的,您可以使用smsgateway或現有的api,您可以在其中從php發出http請求。 有很多短信服務提供商(例如VAS提供商),還有很多免費和開源的短信網關(如kannel),您可以使用它們發送/接收短信,或者也可以配置自己的網關

您需要第三者來發送您的消息,並且您還必須支付一定的發送費用。 我自己還沒有嘗試過,但是本教程通過HTTP發送SMS似乎是一種不錯的方法。 它使您能夠

Use PHP and the HTTP protocol to send text-messages from your website through an SMS gateway.

您可以使用我們的API 由於您已經在通過curl庫使用http請求,因此使用我們為批量sms請求提供的兩個選項之一是沒有問題的(例如,請參見以下答案 ):

完整形式

當您描述要發送的每條消息時,所有遺漏的信息都將從模板中獲取:

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"
  }
}

緊湊的形式

當您僅枚舉電話號碼時,其他所有內容均來自模板:

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

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

請查看本教程 ,以更順利地深入了解API。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM