我在使用 Ozeki Message Server 发送 SMS 时遇到问题。我想多次发送短信,但它只会在我手动重新加载页面时发送。
这是我的代码:
<?php
$balance = mysqli_query($connection, "SELECT * FROM balance WHERE status = 'Installment' OR status = 'No Downpayment' AND schoolyear = '$schoolyear'");
$totalstud = mysqli_num_rows($balance);
for($i=0; $i<$totalstud; $i++)
{
while($row_bal = mysqli_fetch_array($balance))
{
$student_id = $row_bal['student_id'];
$outstanding_balance = $row_bal['outstanding_balance'];
$student = mysqli_query($connection, "SELECT * FROM student WHERE student_id = '$student_id'");
while($row_stud = mysqli_fetch_array($student))
{
$firstname = $row_stud['firstname'];
$lastname = $row_stud['lastname'];
$cp_num = $row_stud['cp_num'];
$schedule = mysqli_query($connection, "SELECT * FROM schedule WHERE schoolyear = '$schoolyear'");
while($row_sched = mysqli_fetch_array($schedule))
{
$date = $row_sched['date'];
$time = $row_sched['time'];
$message = $row_sched['message'];
$message = $firstname . " " . $lastname . " " . $message . "" . $outstanding_balance . ".";
echo "MESSAGE: " . $message . "<br><br>";
$cp[$student_id] = $cp_num;
$msg[$student_id] = $message;
}
}
}
}
for($i=1; $i<=$totalstud; $i++)
{
$gatewayURL = 'http://localhost:9333/ozeki?';
$request = 'login=admin';
$request .= '&password=abc123';
$request .= '&action=sendMessage';
$request .= '&messageType=SMS:TEXT';
$request .= '&recepient='.urlencode($cp[$i]);
$request .= '&messageData='.urlencode($msg[$i]);
$request .= '&sender='.urlencode("OZEKI");
$url = $gatewayURL . $request;
//Open the URL to send the message
file($url);
if($i < $totalstud)
{
//This reloads page
$page = $_SERVER['PHP_SELF'];
$sec = "2";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
//echo "Watch the page reload itself in 10 second!";
?>
</body>
</html>
<?php
}
}
?>
在我的代码中,我从我的数据库中获取数据。$totalstud计算分期付款或无首付的学生总数。这将是发送多少次 SMS 的基础。
但是发生的情况是,消息发送的次数超过了$totalstud。任何人都知道我如何从$totalstud发送短信基地?
假使,假设:
$totalstud = 3;