PHP Classes

SMSGateway: API to send SMS messages using an Android gateway

Recommend this page to a friend!
  Info   View files Documentation   Demos   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-13 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 44 All time: 10,474 This week: 66Up
Version License PHP version Categories
smsgateway 1.0.4GNU Lesser Genera...5.3Networking, PHP 5, Wireless and Mobile
Description Author

This package provides an API to send SMS messages using an Android gateway.

It can handle requests to send SMS messages to a given phone number.

The package can put the messages in a local queue storing the message data in a flat-file structure.

It can also handle HTTP requests as an API server that uses callback functions to process events like when new messages are received, updates in the status of queued messages, and a given timeout period passed after the last time it sees the presence of a phone device.

Recommendations

SMS Messages to Email
Get SMS Messages

Send sms to friends
I have not queries

PHP form to send SMS to users
PHP form to send SMS to users

What is the best PHP email sms class?
Send SMS via email

Recommendation for a PHP class to send sms message
Send SMS with PHP

What is the best PHP sms sending class?
Sending SMS with a PC using a mobile phone

Picture of André Liechti
  Performance   Level  
Name: André Liechti <contact>
Classes: 9 packages by
Country: Switzerland Switzerland
Age: 53
All time rank: 4076 in Switzerland Switzerland
Week rank: 76 Up1 in Switzerland Switzerland Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Details

SMSGateway ? A flat-file based SMS gateway PHP class using an open source Android app

Features

  • SMS gateway using the open source Android app SMS Gateway

License

This software is distributed under the LGPL-3.0-only license. Please read LICENSE for information on the software availability and distribution.

Installation & loading

SMSGateway is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install SMSGateway. Just add this line to your composer.json file:

"multiotp/smsgateway": "^1.0"

or run

composer require multiotp/smsgateway

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of SMSGateway.

Alternatively, if you're not using Composer, you can download SMSGateway as a zip file, then copy the contents of the SMSGateway folder into one of the include_path directories specified in your PHP configuration and load each class file manually:

<?php
use multiOTP\SMSGateway\SMSGateway;

require 'path/to/SMSGateway/src/SMSGateway.php';

Two simple examples

<?php
//Import SMSGateway classes into the global namespace
//These must be at the top of your script, not inside a function
use multiOTP\SMSGateway\SMSGateway;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance
$smsgateway = new SMSGateway();

// Set the data folder
$smsgateway->setDataPath(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);

// Set the shared secret
$smsgateway->setSharedSecret("secret");

$device_id   = "demo";
$to = "+1234567890";
$message = "Demo message";
$device_h = $smsgateway->calculateAuthenticationHash($device_id);

$message_id = $smsgateway->sendMessage($device_id, $to, $message);

echo "Full URL for Android app URL: https://......./?id=$device_id&h=$device_h";

<?php
//Import SMSGateway classes into the global namespace
//These must be at the top of your script, not inside a function
use multiOTP\SMSGateway\SMSGateway;

//Load Composer's autoloader
require 'vendor/autoload.php';

// Please note that implementing a new_message_handling callback function
//  will flag the new messages as read when returning from the function.
function new_message_handling($array) {
  // Handling $array of new received messages
  // [["device_id"    => "device id",
  //   "message_id"   => "message id",
  //   "from"         => "from phone number",
  //   "sms_sent"     => "sms_sent timestamp (ms)",
  //   "sms_received" => "sms_received timestamp (ms)",
  //   "content"      => "message content",
  //   "last_update"  => "last update timestamp (ms)",
  //   "status"       => "UNREAD|READ"
  //  ],
  //  [...]
  // ]
}

function update_handling($array) {
  // Handling $array of status updates for sent messages
  // [["device_id"    => "device id",
  //   "message_id"   => "message id",
  //   "to"           => "to phone number",
  //   "content"      => "content",
  //   "last_update"  => "last update timestamp (ms)",
  //   "status"       => "NEW|PUSHED|PENDING|SENT|DELIVERED|FAILED"
  //  ],
  //  [...]
  // ]
}

function timeout_handling($array) {
  // Handling $array of devices not seen during the last "DeviceTimeout" seconds
  // [["device_id"   => "device_id",
  //   "last_update" => "device_last_update"
  //  ],
  //  [...]
  // ]
}

//Create an instance
$smsgateway = new SMSGateway();

// Set the data folder
$smsgateway->setDataPath(__DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);

// Launch the API server with callback functions definition
$smsgateway->apiServer("secret", "new_message_handling", "update_handling", "timeout_handling");

SMS messages status

Received message

  • UNREAD: message has never been read on the gateway
  • READ: message has already been read on the gateway

Sent message

  • NEW: new created message, not transfered yet to the Android device
  • PUSHED: message pushed to the Android device
  • PENDING: message is pending in the Android device
  • SENT: message has been sent to the gateway's network
  • DELIVERED: message has been received by the recipient's phone
  • FAILED: message delivery has failed and will not be retried

Online demo

A full working gateway implementation is available here : Online SMSGateway demo. Click the link and everything is self-explanatory. You will simply have to install and configure the companion open source Android app in order to send and receive SMS messages through this demo gateway (as explained after sending a first SMS message using the online demo gateway).

Documentation

Example of how to use SMSGateway for a common scenario can be found in the examples folder. If you're looking for a good starting point, we recommend you start with the gateway example.

Changelog

See CHANGELOG.

That's it. You should now be ready to use SMSGateway!

  SMSGateway online demoExternal page  
  Files folder image Files  
File Role Description
Files folder imageexamples (1 file, 1 directory)
Files folder imagesrc (1 file)
Accessible without login Plain text file CHANGELOG.md Doc. Documentation
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me
Accessible without login Plain text file VERSION Data Auxiliary data

  Files folder image Files  /  examples  
File Role Description
Files folder imagedata (1 file)
  Accessible without login Plain text file gateway.php Example Example script

  Files folder image Files  /  examples  /  data  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file SMSGateway.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:10,474
This week:66Up