简体   繁体   中英

i need help in php sending form to send multiple rows

i have an api of sms

<?php

// Configuration variables

$type = "xml";

$id = "92300xxxxxxx";

$pass = "xxxxxxxxxxxx";

$lang = "English";

$mask = "Outreach";

// Data for text message

$to = "$_POST['to']";

$message = "$_POST['message']";


// Prepare data for POST request

$data = "id=".$id."&pass=".$pass."&msg=".$message."&to=".$to."&lang=".$lang."&mask=".$mask."&type=".$type;

// Send the POST request with cURL

$ch = curl_init('http://www.outreach.pk/api/sendsms.php/sendsms/url'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch); //This is the result from Outreach curl_close($ch);

?>

now i make a form

<form method="post">
<input type="text" name="message">
<input type="text" name="to">  --->contact number list 
</form>

now i want to send sms to multiple numbers with this i can send to one number at one time can anyone help me in this matter

You can add more input (or loop it) and set name to array.

<input type="text" name="to[]" />
<input type="text" name="to[]" />
<input type="text" name="to[]" />

Access it by looping through the array

foreach( $_POST['to'] as $key => $val ) {
echo 'send to ' . $val .'<br />';
}
//code not tested

i have solved the issue

$numb = $_POST['to'] $tos = preg_replace('#\\s+#',',',trim($numb)); with this line ^_^

$to = "$tos";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM