如何向多个联系人发送短信

问题描述 投票:0回答:1

如何向多个联系人发送短信并获取每个联系人的结果代码。它不起作用。我只打开“数字”字符串中的最后一个数字,而不是所有数字。

我做错了什么?

在我的控制器中,

  foreach ($sendarraystudent as $studentid) {
      //$i++;
      $student = Student::model()->findByPk($studentid);

      $name = $student->student_firstname . " " . $student->student_middlename . " " . $student->student_lastname;

      $smobile = $student->student_mobile;
      //$mobilelist = $mobilelist . ',' . $smobile;
      $msg1 = $msg;
      $msg1 = str_replace("#course#", $course->course_name, $msg);
      $msg1 = str_replace("#batch#", $batch->batch_name, $msg1);
      $msg1 = str_replace("#name#", $name, $msg1);

      $this->sendbulk($smobile, $msg1);
  }

protected function sendbulk($mobilenum, $message) {
    $no = $mobilenum;
    $msg = $message;

    $link = "http://url/api/v3/index.php?method=sms&api_key=A6xxxxxxxxxxx&to=" . $no . "&sender=xxxxxx&message=" . $msg . "&unicode=xxx";
    header('Location: ' . $link) and exit;
}
php yii
1个回答
4
投票

我认为这是因为你使用了重定向

header('Location: ' . $link) and exit;
。仅处理一条短信。试试这个:

foreach ($sendarraystudent as $studentid) {
    //...
    $link = "http://url/api/v3/index.php?method=sms&api_key=A6xxxxxxxxxxx&to=" . $student->student_mobile . "&sender=xxxxxx&message=" . $msg1 . "&unicode=xxx"
    $content = file_get_contents($link);

    echo $content;
}
© www.soinside.com 2019 - 2024. All rights reserved.