hello need a bit of help on this code, it give an 'insufficient units to send sms.'
hello need a bit of help on this code, it give an 'insufficient units to send sms.'
<?
include "igwt.php";
include "mysql.php";
include "../../api/smsapi.php";
session_start();
$message = $_POST[message];
$to = $_POST[receiver];
$from = $_POST[from];
/* if (strlen($to) == 10)
{
$error[] = "You have to specify the country code, too. Eg. 13333333333";
} */
if ($_SESSION['username'] == '')
{
include "loginerror.php";
die;
exit;
break;
}
$check = mysql_query("SELECT name, firstname, active, sms FROM users WHERE username = '$username'");
$row = mysql_fetch_row($check);
$_SESSION['name'] = $row[0];
$_SESSION['firstname'] = $row[1];
$_SESSION['active'] = $row[2];
$_SESSION['sms'] = $row[3];
$_SESSION['username'] = $username;
$left = $_SESSION['sms'];
$on = $_SESSION['active'];
// check the mobile number
$atom = '[-a-z!#$%&\'*+/=?^_`{|}~]';
if (eregi($atom, $to)) {
$error[] = 'Invalid mobile phone number';
}
if ($left == '0')
{
$error[] = 'Not enough SMS credits to deliver this message.';
}
if (empty ($to)) {
$error[] = 'You not specify destination address (TO)!';
}
if (empty ($from)) {
$error[] = 'You have not specified any sender id!';
}
if (strlen ($message) > 465) {
$error[] = 'Your message is too long';
}
if ($on == 'no')
{
$error[] = 'Your account status is not active.';
}
if ((strlen ($message)) <= 160) {
$balance = 1;
} else { //greater than 160
$count = ((strlen ($message)) / 153);
if ($count <= 3 && $count >2) {
$balance = 3;
}
if ($count <= 2 && $count >1) {
$balance = 2;
}
if ($count <= 4 && $count >3) {
$balance = 4;
}
}
$recipients = explode(",", $to);
$cost = count($recipients) * $balance;
if ($cost > $left) {
$error[] = 'insufficient units to send sms.';
}
if (!$error)
{
mysql_query("UPDATE users SET sms = sms-'$cost' WHERE username = '$username'");
$tudei = date('Y-m-d');
mysql_query("INSERT INTO sms (username, message, date, tono, fromno) VALUES('".$username."','".$message."','".$tudei."','".$to."','".$from."')") or die(mysql_error());
$mysms = new sms();
$results = $mysms->send($to,$from,$message);
}
echo $sus;
?>
hello need a bit of help on this code, it give an 'insufficient units to send sms.'
<?
include "igwt.php";
include "mysql.php";
include "../../api/smsapi.php";
session_start();
$message = $_POST[message];
$to = $_POST[receiver];
$from = $_POST[from];
/* if (strlen($to) == 10)
{
$error[] = "You have to specify the country code, too. Eg. 13333333333";
} */
if ($_SESSION['username'] == '')
{
include "loginerror.php";
die;
exit;
break;
}
$check = mysql_query("SELECT name, firstname, active, sms FROM users WHERE username = '$username'");
$row = mysql_fetch_row($check);
$_SESSION['name'] = $row[0];
$_SESSION['firstname'] = $row[1];
$_SESSION['active'] = $row[2];
$_SESSION['sms'] = $row[3];
$_SESSION['username'] = $username;
$left = $_SESSION['sms'];
$on = $_SESSION['active'];
// check the mobile number
$atom = '[-a-z!#$%&\'*+/=?^_`{|}~]';
if (eregi($atom, $to)) {
$error[] = 'Invalid mobile phone number';
}
if ($left == '0')
{
$error[] = 'Not enough SMS credits to deliver this message.';
}
if (empty ($to)) {
$error[] = 'You not specify destination address (TO)!';
}
if (empty ($from)) {
$error[] = 'You have not specified any sender id!';
}
if (strlen ($message) > 465) {
$error[] = 'Your message is too long';
}
if ($on == 'no')
{
$error[] = 'Your account status is not active.';
}
if ((strlen ($message)) <= 160) {
$balance = 1;
} else { //greater than 160
$count = ((strlen ($message)) / 153);
if ($count <= 3 && $count >2) {
$balance = 3;
}
if ($count <= 2 && $count >1) {
$balance = 2;
}
if ($count <= 4 && $count >3) {
$balance = 4;
}
}
$recipients = explode(",", $to);
$cost = count($recipients) * $balance;
if ($cost > $left) {
$error[] = 'insufficient units to send sms.';
}
if (!$error)
{
mysql_query("UPDATE users SET sms = sms-'$cost' WHERE username = '$username'");
$tudei = date('Y-m-d');
mysql_query("INSERT INTO sms (username, message, date, tono, fromno) VALUES('".$username."','".$message."','".$tudei."','".$to."','".$from."')") or die(mysql_error());
$mysms = new sms();
$results = $mysms->send($to,$from,$message);
}
echo $sus;
?>
Last edited: