2

我正在尝试使用循环发送多条短信,但它不起作用。如果只有一行要获取,那么它可以工作。

代码 :

while ($row = mysql_fetch_array($result)) {

    $dealer_name = $row['dealer_name'];
    $dealer_contact_no = $row['contact_no'];

    $date = new DateTime($row['date']);
    $date = $date->format('d-M-y');
    $due_date = new DateTime($row['due_date']);
    $due_date = $due_date->format('d-M-y');

    //////////////////sms body 

    $msg .= 'Bill Payable-' . "%0A";
    $msg .= 'Bill No:' . $row['ref_no'] . "%0A";
    $msg .= 'Date:' . $date . "%0A";
    $msg .= 'Total Amt:' . $row['total_amount'] . "%0A";
    $msg .= 'Pending Amt:' . $row['pending_amount'] . "%0A";
    $msg .= 'Due Date:' . $due_date . "%0A";
    $msg .= 'Days:' . $row['days'] . "%0A";
    $msg .= '-' . $sender_name;

    $username = "abc";
    $password = "1922345418";
    $text = $msg;
    $phones = $dealer_contact_no;

    if (strlen($phones) == 10) {

        header('Location:http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=' . $username . '&password=' . $password . '&sendername=NETSMS&mobileno=' . $phones . '&message=' . $text . '');
    }
}
4

2 回答 2

4

使用 php file_get_contents

while($row = mysql_fetch_array($result)){
file_get_contents('http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username='.$username.'&password='.$password.'&sendername=NETSMS&mobileno='.$phones.'&message='.$text.'');
}

标头在第一次调用时退出您的循环

于 2015-11-06T07:10:49.123 回答
0

您可以使用cURL

while($row = mysql_fetch_array($result))
{
    $url = 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=' . $username . '&password=' . $password . '&sendername=NETSMS&mobileno=' . $phones . '&message=' . $text;

    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $output = curl_exec($ch);
    curl_close($ch);
}

此处提供了更多使用 cURL 的示例:掌握 cURL 的技术

于 2015-11-06T07:32:53.887 回答