Website updated on: Thursday, July 3, 2008 
On-line manual:

Overview On-line manual On-line support Download Pricing and licensing Contact Us Login
OZEKI NG SMS Gateway - Product Guide

PHP5 and MySQL Contents | SearchReceive SMS on a Website (PHP)

Home > Product Manual > Developers Guide > PHP SMS API > Send SMS from Website (PHP)

SMS Gatway SMS Gateway Home

  Product Manual
  Introduction
  SMS technology
  Installation Guide
  User Guide
  Developers Guide
  ASP SMS API
  PHP SMS API
  Overview
  PHP5 and MySQL
  Send SMS from Website (PHP)
  Receive SMS on a Website (PHP)
  PHP - SQL - SMS on web
  HTTP SMS API
  SQL SMS API
  C Sharp SMS API
  AJAX SMS API
  Tutorials
  Delphi SMS API
  Examples and Solutions
  Appendix
  FAQ
  Commercial Information
  Search

Send SMS from a website (PHP)

Download: sendsms.zip

This guide gives information on how you can add SMS functionality to your website. The method I present uses HTTP communication between the SMS Gateway and your website. To send and receive SMS messages from a webpage you need to have scripting support enabled on your webserver. The scripting support can be PHP or ASP. The examples presented here are using PHP.

How to send SMS from a website?

The example I present here shows how to send an SMS message from your website by clicking on a button. The idea we use is to have an HTML form, that allows the website visitor to enter a telephon number and the message text. This HTML form can be submitted by clicking on the "SEND" button. Once submitted the form variables will be processed by a PHP script. This PHP script will post the SMS message to the SMS Gateway (Figure 1). As you can see on Figure 1. The SMS Gateway and your webserver (your webserver is hosting your HTML Form and your PHP script) can be on two different computers. If you wish you can install the Ozeki SMS Gateway software and the webserver with the HTML Form and the PHP script to the same computer.
Send SMS from a website
Figure 1 - Send SMS from a website


The first step in setting up this system, is to Install the Ozeki NG SMS Gateway to your computer and to verify, that you can send SMS messages from the gateway manually. After your SMS gateway is functioning you can create the HTML Form and the PHP script.

Create the HTML Form for sms sending

To get this solution working you need to save the sendsms.html file into the WWW directory of your webserver. The sendsms.html file will contain the HTML Form that can be used to get the recipient telephone number and the message text from the website visitors. Here is the source of the sendsms.html file:

C:\www\sendsms.html
<html>
 <body>
   <h1>My SMS form</h1>
   <form method=post action='sendsms.php'>
   <table border=0>
   <tr>
     <td>Recipient</td>
     <td><input type='text' name='recipient'></td>
   </tr>
   <tr>
     <td>Message</td>
     <td><textarea rows=4 cols=40 name='message'></textarea></td>
   </tr>
   <tr>
     <td> </td>
     <td><input type=submit name=submit value=Send></td>
   </tr>
   </table>
   </form>
 </body>
</html>


After you save this file, you can use a browser (Internet Exploerer of Firefox) to open it (Figure 2). On the form you will seen an input box for the recipient field and the message text. The recipient field will take the telephone number (e.g. +4407776134588) and the message field will take the message text.


Figure 2 - open the SMS form in your browser

Please note that the form action tag points to the sendsms.php file. This means that the data entered by the website visitor will be posted to the sendsms.php file.

Prepare your PHP SMS script

As you can see the form target in this HTML form is the sendsms.php. The sendsms.php script will get the recipient and the message fields from the form and will build a URL to send the SMS message. This URL will be used to pass the SMS message to the SMS gateway. The URL is invoked in the PHP script using the file command. To get this script working you should configure the $ozeki_url variable to point to the SMS gateway. If you have installed the SMS Gateway to the same computer where your webserver is you can leave this untouched, otherwise you should change the IP address in the URL. The sourcecode of the script is here:

C:\www\sendsms.php
<?php

########################################################
# Login information for the SMS Gateway
########################################################

$ozeki_user = "admin";
$ozeki_password = "abc123";
$ozeki_url = "http://127.0.0.1:9501/ozeki?";

########################################################
# Function used to send the SMS message
########################################################

function ozekiSend($phone, $msg){
      global $ozeki_user,$ozeki_password,$ozeki_url;

      $url = 'username='.$ozeki_user;
      $url.= '&password='.$ozeki_password;
      $url.= '&action=sendMessage';
      $url.= '&messageType=SMS:TEXT';
      $url.= '&recipient='.urlencode($phone);
      $url.= '&messageData='.urlencode($msg);

      $urltouse =  $ozeki_url.$url;

      //Open the URL to send the message
      $resp = file($urltouse);

      echo join("\r\n",$resp);
}

########################################################
# GET data from sendsms.html
########################################################

$phonenum = $_POST['recipient'];
$message = $_POST['message'];

ozekiSend($phonenum,$message);
?>


Once you have both: sendsms.html and sendsms.php installed, you can submit an SMS to the gateway. On a successful send the SMS gateway will return the message reference number (Figure 3). This number can be used to track the message inside the SMS Gateway.


Figure 3 - Successful SMS sending




Next page: Receive SMS on a Website (PHP)
Source: http://www.ozekisms.com/index.php?owpn=327
Copyright © 2000 - 2008 Ozeki Informatics Ltd.
All rights reserved

Legal information        |         Privacy policy        |         Terms of use
Please, address your inquiries to info@ozekisms.com



Cached