xmuzukerx Posted March 23, 2013 Share Posted March 23, 2013 Hello! I wanna create a form that can send sms to multiple recipient, i've created a form that uses javascript to add or remove textbox dynamically, this code successfully send sms when i fill one recipient number, but fails to send more than one recipient, and as i try to make it send sms to more than one user by making it loop, i get this error, Can someone help? i want to know how do i make this form sends sms towards multiple user Warning: Invalid argument supplied for foreach() <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/ Share on other sites More sharing options...
haku Posted March 24, 2013 Share Posted March 24, 2013 Always give the full error including the line number. And make sure to tell us which line that number refers to. Right now you've given us an error and a whack of code, with no way to identify where in that code the error is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420648 Share on other sites More sharing options...
xmuzukerx Posted March 24, 2013 Author Share Posted March 24, 2013 (edited) Sorry, the error is right here, when i try to compile, it says Warning: Invalid argument supplied for foreach() on line 68 <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html> Edited March 24, 2013 by xmuzukerx Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420759 Share on other sites More sharing options...
haku Posted March 24, 2013 Share Posted March 24, 2013 This: foreach ($tel as $_POST['CTL_TEL']) { Should most likely be this: foreach ($_POST['CTL_TEL'] as $tel) { Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420761 Share on other sites More sharing options...
xmuzukerx Posted March 25, 2013 Author Share Posted March 25, 2013 This: foreach ($tel as $_POST['CTL_TEL']) { Should most likely be this: foreach ($_POST['CTL_TEL'] as $tel) { already changed, but still got an error Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420817 Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 Should we start making random guesses as to what that error may be? Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420825 Share on other sites More sharing options...
xmuzukerx Posted March 25, 2013 Author Share Posted March 25, 2013 Should we start making random guesses as to what that error may be? i've known the error but cant find a way to create a foreach loop whereby it will send a sms towards every recipient entered in the form, here's the part where looping is done <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($_POST['CTL_TEL'] as $tel) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420849 Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 And you want us to guess what this error is? What do I get if I am able to guess correctly? Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420853 Share on other sites More sharing options...
xmuzukerx Posted March 25, 2013 Author Share Posted March 25, 2013 Sorry...i'm just asking for help, to create a successful foreach loop that can sent to many recipient...thats all i need Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420889 Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 And how do you expect us to help you when you don't tell us what the error you are seeing is? Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420890 Share on other sites More sharing options...
DaveyK Posted March 25, 2013 Share Posted March 25, 2013 Just tell us what the error is Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420907 Share on other sites More sharing options...
xmuzukerx Posted March 25, 2013 Author Share Posted March 25, 2013 I'll try to explain as detail as i can The error is at the foreach (line 68). whereby it says Warning: Invalid argument supplied for foreach() in C:\xampp\...on line 68 Reason: I want to use the foreach loop in order to send sms to more than one recipient, and when i try, this form can only send sms towards one recipient only, if i add 4 recipient number, it only send sms to the last recipient, the remaining 3 recipient did not get the sms, can someone help me on how to make it send to every recipient <SCRIPT language="javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; element1.name="chkbox[]"; cell1.appendChild(element1); var cell2 = row.insertCell(1); cell2.innerHTML = rowCount + 1; var cell3 = row.insertCell(2); var element2 = document.createElement("input"); element2.type = "text"; element2.name = "CTL_TEL"; cell3.appendChild(element2); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </SCRIPT> <?php error_reporting(E_ALL ^ E_NOTICE); //Example $gsm_send_sms = new gsm_send_sms(); $gsm_send_sms->debug = false; $gsm_send_sms->port = 'COM6'; $gsm_send_sms->baud = 115200; $gsm_send_sms->init(); $name="CTL_TEL[]"; foreach ($tel as $_POST['CTL_TEL']) { $status = $gsm_send_sms->send($_POST["CTL_TEL"] , $_POST["CTL_MSG"]); $status = $gsm_send_sms->send($tel , $_POST["CTL_MSG"]); if ($status) { echo "Message sent\n"; } else { echo "Message not sent\n"; } } $gsm_send_sms->close(); //Send SMS via serial SMS modem class gsm_send_sms { public $port = 'COM6'; public $baud = 115200; public $debug = false; private $fp; private $buffer; //Setup COM port public function init() { $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud"); exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval); if ($retval != 0) { throw new Exception('Unable to setup COM port, check it is correct'); } $this->debugmsg(implode("\n", $output)); $this->debugmsg("Opening port"); //Open COM port $this->fp = fopen($this->port . ':', 'r+'); //Check port opened if (!$this->fp) { throw new Exception("Unable to open port \"{$this->port}\""); } $this->debugmsg("Port opened"); $this->debugmsg("Checking for responce from modem"); //Check modem connected fputs($this->fp, "AT\r"); //Wait for ok $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Did not receive responce from modem'); } $this->debugmsg('Modem connected'); //Set modem to SMS text mode $this->debugmsg('Setting text mode'); fputs($this->fp, "AT+CMGF=1\r"); $status = $this->wait_reply("OK\r\n", 5); if (!$status) { throw new Exception('Unable to set text mode'); } $this->debugmsg('Text mode set'); } //Wait for reply from modem private function wait_reply($expected_result, $timeout) { $this->debugmsg("Waiting {$timeout} seconds for expected result"); //Clear buffer $this->buffer = ''; //Set timeout $timeoutat = time() + $timeout; //Loop until timeout reached (or expected result found) do { $this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}"); $buffer = fread($this->fp, 1024); $this->buffer .= $buffer; usleep(200000);//0.2 sec $this->debugmsg("Received: {$buffer}"); //Check if received expected responce if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) { $this->debugmsg('Found match'); return true; //break; } else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) { return false; } } while ($timeoutat > time()); $this->debugmsg('Timed out'); return false; } //Print debug messages private function debugmsg($message) { if ($this->debug == true) { $message = preg_replace("%[^\040-\176\n\t]%", '', $message); echo $message . "\n"; } } //Close port public function close() { $this->debugmsg('Closing port'); fclose($this->fp); } //Send message public function send($tel, $message) { //Filter tel $tel = preg_replace("%[^0-9\+]%", '', $tel); //Filter message text $message = preg_replace("%[^\040-\176\r\n\t]%", '', $message); $this->debugmsg("Sending message \"{$message}\" to \"{$tel}\""); //Start sending of message fputs($this->fp, "AT+CMGS=\"{$tel}\"\r"); //Wait for confirmation $status = $this->wait_reply("\r\n> ", 5); if (!$status) { //throw new Exception('Did not receive confirmation from modem'); $this->debugmsg('Did not receive confirmation from modem'); return false; } //Send message text fputs($this->fp, $message); //Send message finished indicator fputs($this->fp, chr(26)); //Wait for confirmation $status = $this->wait_reply("OK\r\n", 180); if (!$status) { //throw new Exception('Did not receive confirmation of messgage sent'); $this->debugmsg('Did not receive confirmation of messgage sent'); return false; } $this->debugmsg("Message sent"); return true; } } ?> <html> <head> <title>SMS via GSM</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style> .clbody { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9pt; font-weight:normal; } .clfooter { font-family:Verdana; font-size:7pt; font-weight:normal; } h1, .h1 { width:100%; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; font-weight:bold; } hr, .hr { color:#b0b0b0; } </style> </head> <body class="clbody"> <h1>SMS via GSM</h1> <div style="WIDTH:700px"> </div> <hr size="1"> <?php error_reporting(E_ALL ^ E_NOTICE); ?> <form action="" method="post" name="myForm"> <table class ="clbody" width="700" border="1"> <tr> <td valign="top">Recipient:</td> <td valign="top"> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <TABLE id="dataTable" width="350px" border="1"> <TR> <TD><INPUT type="checkbox" name="chk"/></TD> <TD> 1 </TD> <TD> <input type="text" name="CTL_TEL" value="<?php echo $_GET['CTL_TEL']; ?>"> </TD> </TR> </TABLE> </td> </tr> <tr> <td valign="top">Message:</td> <td valign="top"> <input style="width: 250px" type="text" name="CTL_MSG" value="<?php echo $_GET['CTL_MSG']; ?>"></td> </tr> <tr> <td valign="top">Result code:<font color=green></td> <td valign="top"></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><input size="25" type="submit" value="Send" name="CTL_SEND" style="height: 23px; width: 250px"></td> </tr> </table> <br> <br> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420925 Share on other sites More sharing options...
PaulRyan Posted March 25, 2013 Share Posted March 25, 2013 Firstly, the name of the input elements should be "CTL_TEL[]" NOT "CTL_TEL", this will send an array of value to the processing script. On the processing script, this: foreach ($tel as $_POST['CTL_TEL']) { Should be: foreach ($_POST['CTL_TEL'] AS $tel) { Then that would mean, you only need the following $status variable instead of both: $status = $gsm_send_sms->send($tel , $_POST['CTL_MSG']); Another thing, use some validation, to ensure data coming in to the processing script is exactly what you are expecting. Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420927 Share on other sites More sharing options...
xmuzukerx Posted March 25, 2013 Author Share Posted March 25, 2013 thank you, it worked and does sent sms to each recipient, but may i know what kind of validation that ensure data coming? for example? Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1420942 Share on other sites More sharing options...
DaveyK Posted March 26, 2013 Share Posted March 26, 2013 You can imagine that, if someone were to send a string instead of a number, you would still attempt to send a text to that string, and that would be a bad sitaution, right? Quote Link to comment https://forums.phpfreaks.com/topic/276069-creating-loop-to-send-sms-more-than-one-recipient/#findComment-1421086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.