ianhaney
01-10-2016, 09:51 PM
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
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
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
$response = sendSMS('DJkGc7', '97q84F', '447538503276', "Your PC/Laptop is ready for collection", 'ITDoneRight');
Can anyone help me please as am really stuck with it
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
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
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
$response = sendSMS('DJkGc7', '97q84F', '447538503276', "Your PC/Laptop is ready for collection", 'ITDoneRight');
Can anyone help me please as am really stuck with it