Page 1 of 1

Send message to multiple numbers

Posted: Mon Sep 15, 2008 3:35 am
by drummond
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:

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>&nbsp;</td><td><input type="submit" value="Send SMS">&nbsp;<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);
}
?>
 
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.

Re: Send message to multiple numbers

Posted: Mon Sep 15, 2008 4:28 am
by pcoder
You can take the mobile number by using any seperator like(;).
Then you can easily split these numbers and send it by executing it in a loop.
for example:

Code: Select all

 
$_POST['to'] = "9803525415;9803265256;9803325254";
$mobile_number = split(";",$_POST['to']);
print_r($mobile_number);
 
I think this will help to some extent.

Re: Send message to multiple numbers

Posted: Tue Sep 16, 2008 2:45 am
by drummond
Hi again,

Thanks for the reply I kinda understand what your saying.

I'm getting my numbers from a drop down list and displaying in a textfield.
And the numbers are stored in an array $numberArray.
see below:

Code: Select all

 
<input type="input" name="to" value="<?php echo $row['number'];
$thenumbers = implode(", ", $numberArray);//Display names stored in array from dropdown.php
for($i = 0; $i < count($numberArray); $i++){
}
echo "$thenumbers";
"/>
 
and the SMS code:

Code: Select all

 
<?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 = '***'; 
$msisdnt = '***'; 
 
$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);
}
?>  
 
I have no idea how to loop through these numbers so each number is sent the same message.
I have tried many attempts to no avail but still trying.
I'm trying to use a foreach loop would that be the write direction?
I haven't used loops before and I already hate them! lol