SMS sending script via Goip4 gateway

Here is an example of a script written in PHP, for sending SMS messages through the Goip4 gateway.
The script receives data from the SQL database with a query and alternately sends SMS to each number, and also writes an entry about sending it to a special sms table.

#!/usr/bin/php

<?php

include("config/config.inc.php");
include("config/connect.inc.php");


$Result = mysqli_query($db,
"
SELECT
    abon.first_name,
    abon.second_name,
    abon.id as id,
    abon.depozit as balance,
    abon.id,
    abon.otkl,
    abon.mobile,
    abon.tarif,
    new_tarif.cost_day,
    new_tarif.cost as cost_month,
    new_tarif.dayORmonth as period
FROM
    abon, new_tarif
WHERE
    abon.tarif = new_tarif.id AND abon.state=1 AND abon.killed='' AND abon.tarif=114
"
);


while($Row = mysqli_fetch_array($Result))
{
$user = $Row[id];
$balance =$Row[balance];
$phone = $Row[mobile];

$phone_length=strlen($phone);

if($phone_length==10)
{
$mess_ = "Message text. On your account $balance";
$mess =  rawurlencode($mess_);

print("$phone           $mess_\n");

//test phone
//$phone = "0670000000";
$r = file_get_contents("http://192.168.22.10/goip/en/dosend.php?USERNAME=LOGIN&PASSWORD=PASSWORD&smsprovider=3&goipname=lifecell&smsnum=$phone&method=2&Memo=$mess");
mysqli_query($db, "INSERT INTO sms VALUES(NULL, '$user', '$phone', NOW(), '$mess_', '$balance')");
//print($r);
//exit();

}
}
?>

Содержимое config.inc.php:

<?php
$mysql_host="localhost";
$mysql_user="LOGIN";
$mysql_password="PASSWORD";
$mysql_base="BASE";
?>

Content connect.inc.php:

<?php
$db=mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_base);
mysqli_query($db, "SET NAMES 'utf8'");
?>

See also my articles:
Script to send SMS via Goip4 gateway for ABillS
Installing and configuring GoIP SMS server

Leave a comment

Leave a Reply

Discover more from IT Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading