Send message to multiple numbers
Posted: Mon Sep 15, 2008 3:35 am
Hi I have created an interface that allows users to send an SMS message via the web.
This works fine for one number.
But I want to be able to send messages to multiple numbers that are entered into the text field.
Below is the code I have:
I have created an interface for this service but not the above code.
It was mentioned by a friend I should create an array for the numbers and a function to loop through that array of numbers.
Now I'm pulling my hair out as this is above and beyond me.
Any ideas how to go about this?
Thanks.
This works fine for one number.
But I want to be able to send messages to multiple numbers that are entered into the text field.
Below is the code I have:
Code: Select all
<script language="JavaScript" type="text/javascript">
function countit(what){
document.receive.charcount.value = 64 - document.receive.message.value.length;
}
</script>
<BR><form name='receive' method='post' action='' >
<table>
<tr>
<td>Mobile</td><td><input type="input" name="to" value=""></td>
</tr><tr>
<td>Message</td><td><input type="input" name="message" value="" maxlength="64"></td>
</tr><tr>
<td> </td><td><input type="submit" value="Send SMS"> <input name="charcount" type="reset" id="charcount" value="64" size="5" style="color: #ACA899" readonly="readonly" ></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['to'])){
//exit($_POST['to']);
$url="http://site";
//$url="http://site";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
$user = '***';
$password = '***';
$hidden = '***';
$msisdnv = '***'; # Vodafone
$msisdnt = '***'; # Telecom
$fields ="";
$fields .= 'message=' . htmlentities($_POST['message']) . '&'; # Inputted message
$fields .= 'user=' . $user . '&';
$fields .= 'password=' . $password . '&';
$fields .= 'hidden=' . $hidden . '&';
$to = $_POST['to'];
if (preg_match('/(^021)|(^029)/', $to)) {
$to = preg_replace('/^0/', '64' ,$to); # Removes the 0 and adds
$fields .= 'to=' . $to . '&'; # Inputted mobile number
$fields .= 'msisdn=' . $msisdnv;
} else if (preg_match('/(^025)|(^027)/', $to)) {
$to = preg_replace('/^0/', '64' ,$to); # Removes the 0 and adds
// 64 (cgi script interaction issue)
$fields .= 'to=' . $to . '&'; # Inputted mobile number
$fields .= 'msisdn=' . $msisdnt;
} else {
echo "Not a valid Mobile number";
}
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_USERAGENT, '');
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec ($ch); # This returns HTML
echo $content;
curl_close ($ch);
}
?>
It was mentioned by a friend I should create an array for the numbers and a function to loop through that array of numbers.
Now I'm pulling my hair out as this is above and beyond me.
Any ideas how to go about this?
Thanks.