[英]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.