如何使用php循环发送多个短信

时间:2015-11-07 05:07:01

标签: php bulksms

使用循环发送多个短信时出现问题,无法正常工作..

代码是:

 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 = '';
        $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 = "*********";
        $password = "*********";
        $text = $msg;
        $phones = $dealer_contact_no;

        if (strlen($phones) == 10) {
       $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);
        }
    }

如何反复执行网址发送多条短信.. 请帮助..早些时候我使用了header()函数,但它只适用于单行提取..

1 个答案:

答案 0 :(得分:0)

代码看起来很好。只需检查创建函数,然后调用它就可以调用它。

功能如:

//This function used to send SMS 
function sendSMS($username, $password, $phones, $text){

   $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);
}

从while中删除相同的代码并调用此函数。

循环就像:

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 = '';//Variable initialize with blank...
    $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 Phone number length equals 10 then call send SMS functionality...
    if (strlen($phones) == 10) {
        //Send SMS function calling...
        sendSMS($username, $password, $phones, $text);
    }
}

如果有任何问题/疑问,请告诉我。