I have a problem getting all row values “mobile numbers” from the database and pass though CURL to send messages to multiple recipients.
I have tried calling $row[contact_mobile] where all the data shows when i echo, but when passing though CURL the last number in the database goes though.
So I need assistance to figure out how to pass though all the mobile numbers in the database
Here is my code:
$SQL = "SELECT contact_mobile FROM sms_contacts WHERE group_id = '$group'";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result))
{
$groupsms = $row['contact_mobile'] . ",";
}
$url = "http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0"; // URL to calc.cgi
$fields = array(
'site'=>'',
'username'=>($username),
'password'=>($password),
'message'=>urlencode($text),
'msisdn'=>urlencode($groupsms)
);
$fields_string="?";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
// Check if all data shows
echo $url.$fields.$fields_string;
//execute post
ob_start();
curl_exec($ch);
ob_end_clean();
What i receive:
http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0Array?site=&username=xxxx&password=xxxx&message=the message&msisdn=44123456789%2C&
What it should be like
http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0Array?site=&username=xxxx&password=xxxx&message=the message&msisdn=44123456789,44213456789
Any suggestions on how to solve this?
You could probably have troubleshooted your problem a little bit more before just dropping it here… You just need to replace
by
Since right now you’re assigning
$groupsmsto$row['contact_mobile'] . ","and thus returning the last value only.