-
php sms api mysql issue
Hi
I am using text marketer sms api script and been testing the following script and found it is not working, the scripts are not producing any errors but the sms texts are not being sent, can someone please take a look at the scripts and see where I gone wrong as I can't work it out
Below is my send-sms-message.php script
PHP Code:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
$sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
echo '<form action="send-sms.php" method="post">';
echo '<select>';
echo '<option value="">Choose the mobile number</option>';
while($row= mysqli_fetch_assoc($query)){
echo '<option value="'.$row['customer_name'].$row['customer_phone'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Send SMS">';
echo '</form>';
?>
Below is my send-sms.php script
PHP Code:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
function sendSMS($username, $password, $mobnumber, $message, $originator) {
$URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml";
$URL .= "&to=$mobnumber&message=".urlencode($message).'&orig='.urlencode($originator);
$fp = fopen($URL, 'r');
return fread($fp, 1024);
}
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
$sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
//fetch the data from the database
while ($row = mysqli_fetch_array($query)) {
$mobnumber = $row['customer_phone'];
$country_code = '44';
$mobnumber = str_replace(' ', '', $row['customer_phone']);
$mobnumber = substr_replace($mobnumber, ''.$country_code, 0, ($mobnumber[0] == '0'));
//var_dump($mobnumber);
}
$message = "Name:".$row['customer_name'] . ' ' . 'Your PC/Laptop is ready for collection';
// Example of use
$response = sendSMS('DJkGc7', '97q84F', $mobnumber, "Your PC/Laptop is ready for collection", 'ITDoneRight');
var_dump($response);
?>
If I hard code the mobile number in as per the script below, the SMS works and comes through but need it to send the SMS to the mobile number I select from the select menu on the send-sms-message.php page
PHP Code:
$response = sendSMS('DJkGc7', '97q84F', '447538503276', "Your PC/Laptop is ready for collection", 'ITDoneRight');
Can anyone help me please as am really stuck with it
-
UPDATE:
Hi, sorry got a update, it seems to be working now but I think it is looping cause of the while code in the send-sms-message.php and send-sms.php scripts and sending to all numbers and not just the one I choose within the select menu, is it possible just to check the code please
below is the send-sms-message.php script
Code:
<?php
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
$sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
echo '<form action="send-sms.php" method="post">';
echo '<select name="customer_phone">';
echo '<option value="">Choose the mobile number</option>';
while($row= mysqli_fetch_assoc($query)){
echo '<option value="'.$row['customer_phone'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Send SMS">';
echo '</form>';
?>
below is the send-sms.php script
Code:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
function sendSMS($username, $password, $customer_phone, $message, $originator) {
$URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml";
$URL .= "&to=$customer_phone&message=".urlencode($message).'&orig='.urlencode($originator);
$fp = fopen($URL, 'r');
return fread($fp, 1024);
}
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
$sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
//fetch the data from the database
while ($row = mysqli_fetch_array($query)) {
$customer_phone = $row['customer_phone'];
if (isset($_POST["submit"])) {
//var_dump($customer_phone);
}
// Example of use
$response = sendSMS('DJkGc7', '97q84F', $customer_phone, 'Your PC/Laptop is ready for collection', 'ITDoneRight');
//var_dump($response);
}
?>
-
Hi
I have got it sort of working but the previous script was looping through all the records instead of a specific one so now I altered my send-sms-message.php script to the following but with that I got a undefined index: id error
Code:
<?php
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
}
$smsid = $db->real_escape_string($_GET['id']);
$sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs WHERE id = '$smsid'";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
echo '<form method="get" action="send-sms.php">';
echo '<select>';
echo '<option value="">Choose the mobile number</option>';
while($row= mysqli_fetch_assoc($query)){
echo '<option name="id" value="'.$row['id'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Send SMS">';
echo '</form>';
?>