OZEKI NG SMS Gateway
"The World's most reliable SMS gateway software!"
info@ozekisms.com
Tel.: 00 36 52 532 731
Overview Quick start Download Manual How to buy FAQ Contact Us
OZEKI NG SMS Gateway - Product Guide

PHP5 and MySQL Contents | SearchPHP - SQL - SMS on web

Home > Product Manual > Developers Guide > PHP SMS API > Receive SMS on a Website (PHP)

SMS Gateway SMS Gateway Home

PHP Developers!

Start by checking out the possible solutions on how to add SMS functionality to your website. Read the quick overview:

php sms example Beginners: How to send/receive SMS with PHP...


Send SMS using HTTP:

With PHP you can easily submit SMS messages using HTTP requests:

Send SMS (PHP + HTML form)
Send SMS (URL examples)


The Ozeki NG SMS Gateway can send incoming messages to your PHP website through HTTP GET and POST requests:

Receive SMS using PHP and HTTP


SMS from MySQL:

If your website has a MySQL database, check out the following information:

Send SMS from MySQL


 


Automated phone calls?
Ozeki Phone System XE VoIP PBX software is an advanced PBX built for automated voice calls and 2 way SMS messaging. It has outstanding APIs for software developers. It can be used for:

Phone calls from SQL
Phone calls from HTTP
Voice and SMS applications

Callcenter developers
If you are working on telephone solutions, please check out the Ozeki VoIP SIP SDK.
It can be used to create VoIP client and server software.

Contact Us!
If you wish to get further information, do not hesitate to contact us!

E-mail: info@ozekisms.com

If you have a technical question, please submit a support request on-line.

Receive SMS on a website (PHP)


This guide explains how you can create an SMS service using PHP that processes incoming SMS messages. It explains the configuration of the SMS gateway and gives you instructions on how you can process SMS messages in your PHP script. The guide is aimed at software developers who are familiar with the PHP programming language.

Introduction

PHP is usually used in web development environments. It is quite common that a PHP script is called when a webpage is requested. Often this PHP script is interacting with a database, such as MySQL to store and retrieve information to be displayed on the website. The solution I am going to present here for SMS messaging assumes you are hosting your PHP script on a webserver and you prefer to receive SMS messages over HTTP request. If your PHP script is using a database server for data storage, you might want to consider to setup an SQL SMS Gateway for sending and receiving SMS messages. This topic is covered in detail in the following guide: SQL - SMS Gateway. This guide gives instructions on how you can create an HTTP - SMS Gateway configuration based on Ozeki NG SMS Gateway (Figure 0).


Figure 0 - How to receive an SMS from a website

Getting started

To start first you need to setup a hosting environment for your PHP script. This includes the installation of the following components:

1.) Apache webserver
2.) PHP programming language

You also need to download and install Ozeki NG SMS Gateway!

Ozeki NG SMS Gateway can be obtained by
opening the download page:
Download Ozeki NG SMS Gateway!

After these components are installed, you will have a WWWRoot directory that can be used to host PHP scripts. I assume you have configured Apache to use "C:\www\" as the WWWRoot directory.

Testing your hosting environment

To test your hosting environment save the smsresponse.php PHP script in C:\www\.

C:\www\smsresponse.php
<?php

  $sender = $_GET['sender'];
  $message = $_GET['msgdata'];

  if ($sender!='') {
     #
     # Save incoming messages
     #
     $fp = fopen("receivelog.txt","a");
     fputs($fp,"$sender $message\n");
     fclose($fp);

     #
     # Return a response SMS message
     #
     $responsetext = "Thank you for the message!";
     echo "{SMS:TEXT}{}{}{".$sender."}{".$responsetext."}";
  } else {
     echo "The PHP script is ready for accepting messages";
  }

?>
Figure 1 - Source code of the PHP SMS receiver script.

If you have saved the smsresponse.php file into your WWWRoot directory (C:\www) you can test your script by using Internet Explorer. In Internet Explorer you should open the URL pointing to your script. This URL is:

http://127.0.0.1/smsresponse.php

If your hosting environment is working and your PHP script is successfully installed, you should see the following text: "The PHP script is ready for accepting messages" (Figure 2.). This text is displayed in your browser.


Figure 2 - Testing the SMS receiver script in a browser.

Configuring the SMS Gateway

Once your PHP script is ready for accepting incoming messages, you should install and configure the SMS gateway. The SMS gateway will pass incoming SMS messages to your PHP script using HTTP requests, this is why we call this configuration HTTP-SMS Gateway configuration. To install the SMS gateway you should perform the following steps:

After these steps are complete you can configure the SMS gateway to pass incoming messages to the smsresponse.php PHP script. Incoming messages will be forwarded to this PHP script using the HTTP GET method. The SMS Gateway has an HTTPClient user that has the functionality we need. To get the HTTPClient user to work for us we need to add it to our configuration. To do this click on "Add" in the top right hand corner of the "Users and Applications" panel of the SMS Gateway management console (Figure 3.).


Figure 3 - adding a new user.

This will bring up the "Add user or application" form. In this form you should select the HTTP Client user and click on install (Figure 4).


Figure 4 - installing the HTTPClient user.

To install the HTTPClient user you need to provide a unique user name. I recommend to use "myphp" for this (Figure 5). Ozeki NG SMS Gateway allows you to configure many HTTP client users. This is useful if you wish to use many different PHP applications. You can configure one HTTP Client user for every PHP application that is responsible for providing SMS services and you can use the inbound routing configuration to decide which messages should be received by which user.



Figure 5 - providing a unique name for the HTTPClient user.

After the HTTPClient user has been created, you should configure the URL that points to your PHP application (Figure 6). In our case this will be:

http://127.0.0.1/smsresponse.php?sender=$originator&receiver=$recipient&msgdata=$messagedata&recvtime=$receivedtime&msgid=$messageid

Please note that this URL contains keywords, such as $originator, $recipient, $messagedata, etc... These keywords will be replaced in the URL to the actual values of the incoming messages before the URL is called to forward the message to your PHP script. A complete list of keywords you can use is listed in the HTTP Client user documentation.


Figure 6 - URL pointing to the PHP application.

After setting the URL your system is ready to operate.

Testing your configuration

If you wish to test your configuration, the first thing you want to do is to see the HTTP communication between the SMS Gateway and your PHP script. To see this communication, you should enable "low level communication logging" in the HTTPClient user configuration form. You can enable low level communication logging by clicking on the "Logging" tab (Figure 7) of the form and checking the "Log low level communication" checkbox.


Figure 7 - Enabling low level communication logging

After the low level communication logging is enabled you are ready to send your first SMS message. When you send your SMS message to the system from your mobile phone, the GSM Modem connection of the SMS gateway will receive it (Figure 8). The GSM Modem connection will forward the message to the inbound routing table. The inbound routing table will find the matching inbound routing rule and will forward the SMS to the HTTPClient user. The final step is performed by the HTTPClient user who will forward the message to the smsresponse.php script using an HTTP GET request.


Figure 8 - Testing the pipeline

Checking the logs

Since you have enabled low level communication logging in the HTTPClient user configuration form you can use the event viewer of the SMS Gateway to see the HTTP request that was used to pass the message to your PHP script. The event viewer also displays the HTTP response, which is useful if you are looking for errors. The event viewer can be opened in two ways: You can use the menu (Figure 9) or you can click on the "events" link in the user data sheet.


Figure 9 - Viewing server events.





Next page: PHP - SQL - SMS on web
Copyright © 2000 - 2014 Ozeki Informatics Ltd.
All rights reserved

Software PBX for Windows | VoIP SDK   |   Legal information   |   Privacy policy   |   Terms of use
Please, address your inquiries to info@ozekisms.com