Products
Ozeki 10
Apps
Chat
SMS Gateway
Quick Start Guide
SMS with Client Software
HTTP API
SMS from/to Database
PHP SMS API
SMS from Website (MySQL, PHP)
SMS from Website (HTTP API, PHP)
Send SMS from HTTP API withPHP
Solutions
C# SMS API
VB.NET SMS API
SQL Logging
System Database
Robot Controller
Softphone
PBX
Connections
Installation guide
Terms and Definitions
HTTP API
SMS
Bulk Messenger
Cluster
Developer tools
Robots
Hardware
Installer
Technology
Company


Ozeki 10 - SMS Gateway server software
SMS from Website (MySQL, PHP) SMS from Website (MySQL, PHP) | Send SMS from HTTP API withPHP Send SMS from HTTP API withPHP

Use your website to send SMS

You can add SMS functionality to your website. This method presents how to use a PHP script to communicate with Ozeki SMS Gateway's HTTP API. First you need to enable the PHP scripting support on your webserver.

Download: sendsms.zip

Start the video

The presented example shows how message sending can work from your website by clicking 'Send'. The idea uses a HTML form. The user can fill this HTML form and click 'Send'. The PHP script processes the two variables in the textboxes called 'Recipient' and 'Message'. It also sends the generated HTTP request URL to the HTTP API of Ozeki SMS Gateway (Figure 1). Your webserver and Ozeki SMS Gateway can be on two different machines or on the same machine as well.

Send SMS from a website
Figure 1 - How an SMS can be sent from your website

You should install Ozeki SMS Gateway in the first place and check if you can manually send SMS messages from it. Then please download the HTML+PHP script to create and use the SMS sending form.

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

Create the HTML Form for sms sending

Please save sendsms.html to get started with this solution. You should save it in the 'WWW' directory of your webserver. What does it contain? It cointains the HTML form with a recipient and message textbox, plus a 'Send' button (Figure 2).

<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>
Figure 2 - The source of *\WWW\sendsms.html

If you have successfully saved this file in your webserver's directory, you can open it in any webbrowser (Figure 3). You can add any telephone number to the recipient field (e.g. +4407776134588) and write your message text in the next textbox.


Figure 3 - How the SMS form should look like

The form tag's action attribute points to sendsms.php. Which means that the data entered on the form will be forwarded to sendsms.php. The data will be sent to the HTTP API if 'Send' is pressed.

How to prepare your PHP SMS script

'sendsms.php' is the target for the recipient and message fields. This PHP script can build an URL for Ozeki SMS Gateway's HTTP API. It will invoke the URL if 'Send' is pressed. Do no forget to configure $ozeki_user, $ozeki_password and $ozeki_url variables. In case Ozeki SMS Gateway and your webserver runs on the same machine, you can leave $ozeki_url untouched. Otherwise you should change the IP to the IP address of Ozeki SMS Gateway's machine. The newest version of Ozeki SMS Gateway uses port 9505, while 9501 belongs to the older one.

<?php

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

$ozeki_user = "admin";
$ozeki_password = "abc123";
$ozeki_url = "http://127.0.0.1:9505/api?";

########################################################
# Functions used to send the SMS message
########################################################
function httpRequest($url){
    $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
    preg_match($pattern,$url,$args);
    $in = "";
    $fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
    if (!$fp) {
       return("$errstr ($errno)");
    } else {
        $out = "GET /$args[3] HTTP/1.1\r\n";
        $out .= "Host: $args[1]:$args[2]\r\n";
        $out .= "User-agent: Ozeki PHP client\r\n";
        $out .= "Accept: */*\r\n";
        $out .= "Connection: Close\r\n\r\n";

        fwrite($fp, $out);
        while (!feof($fp)) {
           $in.=fgets($fp, 128);
        }
    }
    fclose($fp);
    return($in);
}



function ozekiSend($phone, $msg, $debug=false){
      global $ozeki_user,$ozeki_password,$ozeki_url;
	  
      $url= 'action=sendmessage';
      $url.= '&username='.$ozeki_user;
      $url.= '&password='.$ozeki_password;      
      $url.= '&messagetype=SMS:TEXT';
      $url.= '&recipient='.urlencode($phone);
      $url.= '&messagedata='.urlencode($msg);

      $urltouse =  $ozeki_url.$url;
      if ($debug) { echo "Request: <br>$urltouse<br><br>"; }

      //Open the URL to send the message
      $response = httpRequest($urltouse);
      if ($debug) {
           echo "Response: <br><pre>".
           str_replace(array("<",">"),array("&lt;","&gt;"),$response).
           "</pre><br>"; }

      return($response);
}

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

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

ozekiSend($phonenum,$message,$debug);

?>
Figure 4 - The source code of the *\WWW\sendsms.php script

After both sendsms.html and sendsms.php are copied and modified at *\WWW\, an SMS message can be submitted by the gateway. After it gets accepted for delivery, the SMS Gateway will return the message reference number in the response (Figure 5). Messages are tracked in Ozeki SMS Gateway by their reference number.


Figure 5 - Response XML from Ozeki SMS Gateway

Copyright © 2000- - Ozeki Ltd | info@ozeki.hu
Home > Products > Ozeki 10 > Apps > SMS Gateway > PHP SMS API > SMS from Website (HTTP API, PHP)
Legal | Privacy policy | Terms of use
Page: 5722 | Login | 3.93.74.227