Using foreach to send sms to multiple users

Hello guys, please want help

I am new to PHP so just doing a project need to send sms to all of the users so that we can let them know our new offers or news some thing like that.
using mysql and php, please help with so many thanks in advance:)

Sorry, is there a question in there? :slight_smile:

Regarding the code yeah how to this idea?

Just loop through the addresses and add them as Bcc email recipients. That way you only send one email instead of one per person.

BTW - if you want someone to write code for you, then check out the Marketplace to hire someone. Otherwise try to code what you want, fail, then come here for advice on how to make YOUR code work. :wink:

Yeah but using a script :slight_smile:

So see my 2nd paragraph in my previous post. :slight_smile:

Thanks for the idea

<?php

if (!$link = mysql_connect(‘localhost’, ‘root’, ‘’)) {
echo ‘Could not connect to mysql’;
exit;
}

if (!mysql_select_db(‘DB’, $link)) {
echo ‘Could not select database’;
exit;
}

$sql = “SELECT mobile FROM ias_mobile” ;
$result = mysql_query($sql, $link);

if (!$result) {
echo "DB Error, could not query the database
";
echo 'MySQL Error: ’ . mysql_error();
exit;
}

while ($row = mysql_fetch_array($result)) {

 echo $row['mobile'];
 echo "&lt;br&gt;";

//UNTIL HERE IT’S WORKING
//$row = “INSERT INTO sms_notify VALUES(‘[mobile]’)”; HERE I NEED TO INSERT THE
//SAME DATA DISPLAYED FROM THE PREVIOUS TABLE TO INSERT IT TO ANOTHER TABLE IT IS NOT WORKING

}

mysql_close($link)

?>

<?php
$link = @mysql_connect('localhost', 'root', '') or die ('Could not connect to mysql');

@mysql_select_db('DB', $link) or die ('Could not select database');

$sql = "SELECT mobile FROM ias_mobile" ;
$result = mysql_query($sql, $link);

if (!$result) {
echo "DB Error, could not query the database\
";
echo 'MySQL Error: ' . mysql_error();
exit;
}

while ($row = mysql_fetch_array($result)) {
$mobile = $row['mobile'];
echo $mobile;
echo "<br>";
$sql = "INSERT INTO sms_notify (FieldName) VALUES ('" . $mobile . "')"; // Change FieldName to your actual field name
mysql_query ($sql, $link);
}
mysql_close($link);
?>

You did it siteguru thanks lot lot

you achieved for me the first step and it is done, now hope you help me since i am selecting the mobile, the next phase whis is using the following code want to send to the same mobiles a message which is sent using foreach or what can be else, WITH REGARDS

<?
$url=“gateway”;
$login=“Login”;
$pwd=“pwd”;
$mittente=“company”;
$numero=“$cellulare”;
$testo=urlencode($messaggio);
$y=“login=”.$login.“&pwd=”.$pwd.“&testo=”.$testo.“&numero=”.$numero.“&mittente=”.$mittente;
$contents = @file_get_contents($url.“?”.$y);
print $contents;
?>

Erm, couldn’t you simply…


INSERT INTO sms_notify (number) SELECT user.mobile FROM user

Yes thanks its done

hgh

Help needed

So what is going wrong? What is happening that should not. What is not happening that should? Do you get any error messages? If yes, what are they?

No there is no wrong everything is right, but regarding the loop arouns the records and the code of SMS SENDER that i posted, that is my point, help needed, thanks

You’ll find people will be more willing to help if you have a go at writing some code first. No-one expects your code to be 100% first-time, but people do expect you to try.

It should be fairly simple, just take the SMS API code, and put it in a foreach loop. If you get stuck, show us how far you’ve gotten, and I’m certain someone will help you out.

:slight_smile:

Thanks LSC-Rob sure i will do that…

THIS IS THE CODE DEAR DEVELOPERS HELP NEEDED

<?php
$link = @mysql_connect(‘localhost’, ‘root’, ‘’) or die (‘Could not connect to mysql’);

@mysql_select_db(‘radius senza lock’, $link) or die (‘Could not select database’);

$sql = “SELECT mobile FROM staff” ;//here selecting mobile numbers IT"S WORKING
$result = mysql_query($sql, $link);

if (!$result) {
echo "DB Error, could not query the database
“;
echo ‘MySQL Error: ’ . mysql_error();
exit;
}
while ($row = mysql_fetch_array($result)) {
$mobile = $row[‘mobile’];
echo $mobile;
echo “<br>”;
$sql = "INSERT INTO sms_notify (mobile) VALUES (’” . $mobile . “')”;// inserting mobile numbers from the previous table to the smsnotify IT’S WORKING
mysql_query ($sql, $link);

}
mysql_close($link);// here it is not working or the work is here i am doing loop foreach to send the sms to the users in every row
$array = array( );
foreach( $array as $[mobile] )
{
echo “Value is $value <br />”;
}
?>

In relation with upper code of the gateway code details