1

There is a problem with send multiple SMS using loop, not working..

the codes are :

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

How to execute the url again and again to send multiple SMS.. please help.. earlier i used header() function but it works only with single row fetched..

1 Answers1

0

Code is looking fine. Just check with create function for piece of code pick from while and call it.

Function like:

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

And remove same code from while and call this function.

Loop is like:

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

Let me know if any concern/query.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • What is the result? Any Error, Notice, Something related to it? Have you able to try with exit(); after while? Please check it how many time looping. – AddWeb Solution Pvt Ltd Nov 07 '15 at 06:21
  • i think the curl is not working.. i haven't used this before.. is it need some helper file?? –  Nov 07 '15 at 06:25
  • Nope, This is PHP function no require helper file. See: http://php.net/manual/en/curl.examples.php – AddWeb Solution Pvt Ltd Nov 07 '15 at 06:27
  • if i echo the $url then i got 3 row means the loop is working.. but no sms send –  Nov 07 '15 at 06:42
  • So we have final option to check cURL is work fine OR not? and for that please use: if($output){ // ?? - if request and data are completely received print(' :: Message send for '. $phones .':: '); } And let me know if need further. – AddWeb Solution Pvt Ltd Nov 07 '15 at 06:50
  • If you have shell access to the machine your PHP script is running from, run the following command: curl -I 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=USERNAME&password=PASSWORD&sendername=NETSMS&mobileno=MOBILENO&message=TEXT' This will output the response headers, which may contain some clue as to why your request is failing. NOTE: Replace capital string with actual. – AddWeb Solution Pvt Ltd Nov 07 '15 at 07:04