多次发送短信

时间:2015-09-05 12:22:17

标签: php sql sms ozeki

我在使用Ozeki Message Server发送短信时遇到问题。我想多次发送短信,但只有在我手动重新加载页面时才会发送。

这是我的代码:

        <?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 ,用于计算分期付款或无首付款的学生总数。这将是短信发送次数的基础。

但是发生的情况是,邮件的发送次数超过了 $ totalstud 。任何人都知道如何从 $ totalstud 发送短信基础?

假设:

$totalstud = 3;

0 个答案:

没有答案