Example of connecting to the Atomic SMS Sender 3.0 gateway for PHP

You need to have basic knowledge in PHP for easy integration of the sms gateway into your project. Anyway our experts are always ready to help you with the integration. If you have any problems or questions please contact our technical support.

Below is a sample PHP code showing the capabilities of the SMS gateway. Our experts prepared a special PHP class to make integration of SMS messaging into your project as easy as possible.

Download the PHP Class

Please note that it is necessary to make changes in the "config.php" file before using the class. You need to fill in the values for variables "$sms_key_private", "$sms_key_public", found in your Member Area in SMS Sender Settings. make sure to enable XML interface. Use UTF-8 charset for communication with the server.

The example of class usage

<?php

include 'config.php';

include 'Addressbook.php';

include 'Exceptions.php';

include 'Account.php';

include 'Stat.php';

$Gateway=new APISMS($sms_key_private,$sms_key_public,

'

$Addressbook=new Addressbook($Gateway);

$Exceptions=new Exceptions($Gateway);

$Account=new Account($Gateway);

$Stat = new Stat ($Gateway);

//First of all we register the sender name before delivering SMS

// including Ukraine

//If you are going to send sms only to Russia

//the sender name registration is unnecessary

$res=$Account->registerSender('testName','ua');

//Check if the operation is successful

if (isset($res["result"]["error"])) {

die ("Error: ".$res["result"]["code"]);

}

//Create the Address Book

$res=$Addressbook->addAddressBook('Test book');

//Check if the operation is successful

if (isset($res["result"]["error"])) {

die ("Error: ".$res["result"]["code"]);

} else {

//Get the Address Book id

$addrbook_id = $res["result"]["addressbook_id"];

}

//Add some phone numbers for the delivery

$res=$Addressbook->addPhoneToAddressBook($addrbook_id,

'79010000001', 'John;Brown;');

if (isset($res["result"]["error"])) {

echo ("Error: ".$res["result"]["code"]."<br>");

}

$res=$Addressbook->addPhoneToAddressBook($addrbook_id,

'79010000002', 'Albert;Grange;');

if (isset($res["result"]["error"])) {

echo ("Error: ".$res["result"]["code"]."<br>");

}

//Check the account balance

$res=$Account->getUserBalance();

if (isset($res["result"]["error"])) {

echo ("Error: ".$res["result"]["code"]."<br>");

} else {

echo ("Balance: ".$res["result"]["result"]["balance_currency"]."

".$res["result"]["result"]["currency"]);

$balance = $res["result"]["balance_currency"];

}

//Check if there is enough money for the delivery you planned

$res = $Stat->checkCampaignPrice("testName",

"Test the sms delivery via Atomic SMS Sender",

$addrbook_id);

if (isset($res["result"]["error"])) {

die ("Error: ".$res["result"]["code"]."<br>");

} else {

$cost = $res["result"]["price"];

}

if ($balance > $cost) {

//Sending sms messages to the current Address Book

$res = $Stat->createCampaign("testName",

" Testing sms delivery via Atomic SMS Sender",

$addrbook_id, "", 0, 0, 0, "");

if (isset($res["result"]["error"])) {

echo ("Error: ".$res["result"]["code"]."<br>");

} else {

$campaign_id = $res["result"]["id"];

}

//Now you can get the delivery reports.

//It's clear you should wait for some time

//for status update,

//just save "$campaign_id" and run the request later.

$res = $Stat->getCampaignDeliveryStats($campaign_id);

//if you run the request immediately, you'll get JSON

//that will look like this

/*

{

"result":{

"phone":["79010000001","79010000002"],

"sentdate":["0000-00-00 00:00:00","0000-00-00 00:00:00"],

"donedate":["0000-00-00 00:00:00","0000-00-00 00:00:00"],

"status":["0","0"]

}

}

//It means the campaign is still in the delivery queue

*/

} else {

//not enough money to send the campaign

}

?>

Download the Class