How to Send and Read SMS Using PHP with MOBITEK SMS Engine Basic Edition


REVISION HISTORY

EDITION

DATE

REMARK

1st

13th January 2016

Draft release

 

COPYRIGHT

© 2015 MOBITEK System Sdn. Bhd. All rights reserved.

No part of this document may be reproduced, distributed, stored in a retrieval system or translated into any language, in any form or by any means, electronic, mechanical, magnetic, optical, photocopying, manual or otherwise, without the prior written permission of MOBITEK System Sdn. Bhd.

 

TRADEMARKS

MOBITEK® is a registered trademark owns by MOBITEK System Sdn. Bhd.

Product names, logos, brands and other trademarks referred in this document are the property of their respective trademark holders and are used only to directly describe the products being provided.

 

DISCLAIMER

MOBITEK makes no representations or warranties with respect to the contents hereof and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose.

Furthermore, MOBITEK reserves the right to revise this publication and to make changes from time to time in the contents hereof without obligation to notify any person of such revision or changes.

 

ACKNOWLEDGEMENT

We like to extend our appreciation to the following persons for their contribution in revising this manual:-

 

  1. Ms. Nur Shafiqah binti Muhamad Baharum, UNIVERSITI PERTAHANAN NASIONAL MALAYSIA

 

SCOPE OF THIS MANUAL

Setting up the PHP and SMS Engine Basic Edition in 64 bit OS using Wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-for 32 bit

 

INTRODUCTION

SMS Engine Basic Edition is a Windows application that sends and receives SMS. System integrator and software developer (SI/SD) do not need to write any code to build a SMS Gateway. The SMS Engine uses MS Access database – “SMSEngine5.mdb” to store incoming SMS, and to check if there is any pending SMS to be send out. SI/SD only needs to insert record into database to send out SMS, and retrieve record from database to read SMS. The SMS Engine has taken care all SMS transactions.

PHP programmers can develop a SMS Gateway or SMS application by using PHP with SMS Engine. PHP programmers need only to interact with the database via ODBC to send and read SMS. A sample code written in PHP is provided with the SMS Engine. PHP programmers can freely use, or modify the code.

 

SYSTEM REQUIREMENTS

  1. SI/SD must posses knowledge of PHP, database programming and SQL statement

  2. SMS ENGINE Basic Edition version 5

  3. wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-for 32 bit

  4. PC running on Windows 64 bit

 

GUIDE FOR HANDLING PHP AND SMS ENGINE IN 64 BIT OS

This section will guide you on the installation of PHP with Apache. In this guide, we will use WAMP (https://www.wampserver.com/en/download.php) to install PHP and Apache. Please make sure you are downloading the WAMP server 64 bit.

 

Install Apache and PHP using WAMP

  1. Run the “wampserver3.1.9.exe”.
  2. Follow the on-screen instructions to install the WAMP Server.

Note: WAMP means Windows, Apache, MySQL and PHP

 

Add a new folder

Add a new folder in “C:wampwww”, and name it as “PHPSMS”. E.g. “C:wampwwwPHPSMS”

 

Install SMS Engine Basic Edition

  1. Run the “Setup.exe”.
  2. DO NOT install the SMS Engine version 5 at the default location – “C:Program Files(x86)”. The engine must be installed on the web server’s directory.
  3. Change the default destination folder for SMS Engine by click on Browse button.

  4. Browse the path and save it inside “C:wampwwwPHPSMS”.
  5. Then, a new destination folder will created.

 

Configure ODBC

    1. Click Start, search for “odbc” and click on ODBC Data Sources (64-bit).
    2. Choose System DSN tab, then click on Add button.
    3. Find the Microsoft Access Driver(*.mdb, *.accdb) then click Finish button.
    4. Type “SMSEngine5”into a field provided then click on Select button.
    5. Locate the directories of the database, select “SMSEngine5.mdb” database and click OK button.
    6. The directory of the database SMSEngine5 will appear. Then click the OK button..
    7. After completed, click the OK button.

 

Installing PHP code

    1. Copy these files to the directory — “C:wampwwwPHPSMS”:
      • Index.html
      • Outbox.html
      • Outbox.php
      • ReadAllSMS.php
      • ReadNewSMS.php
    2.  Open and edit the Outbox.php, ReadAllSMS.php, ReadNewSMS.php and SendSMS.php.

      Change the ‘SMSEngine3’,”,” to ‘SMSEngine5’,”,” for all the php codes.

 

RUN THE WAMPSERVER

  1. Click start and search for your wamp server. Start wampserver3.1.9.
  2. Find your wampserver in the tray panel. Make sure the ‘W’ icon is turned into green colour that indicates the services are running.

    Note: If your ‘W’ is not turned to green colour, click to the logo and click at “Start All Services”

  3. WAMPSERVER 3.1.9 64-bit is using PHP version 7.x, change it  to version  5.6.40. Hover to “PHP” -> “Version” -> “5.6.40”.

  4. Run the local host
    • In tray panel, click wamp logo
    • Click Localhost
  5. Your localhost will appear on web browser like below.
  6. Change the address and click enter in order to go to the PHPSMS.
  7. Now, you can see all the 4 links which is linked to the 4 php code that you already copy in “C:/wamp/www/PHPSMS”.

 

RUN THE SMS ENGINE

  1. Run the SMS Engine
  2. Click on Setting then choose SMS Modem Setting.
  3. After finish up configure the GSM modem, click on Save Setting button.
  4. Click on Start button.
  5. After that, run a web browser e.g. Internet Explorer then type “http://localhost/PHPSMS/Index.htm”.
  6. To read a new SMS, just click on Read New SMS link.
  7. The new incoming SMS will display in this page.
  8. In order to view all the incoming SMS that have been read, click on Read ALL SMS link.
  9. The status message is changed from “NEW” to “READ”.
  10. In order to send the SMS to any recipient, click on Send SMS link.
  11. Type the mobile and the message in the text box provided. Then, click Send button.
  12. The message will queue at a while and will send soon by the SMS Engine.

  13. Now, you can see your send SMS is successful through the SMS Engine
  14. In order to send the Outbox, click on DISPLAY ALL OUTGOING SMS .
  15. Now, you can see also the Delivery status from web browser like below.

 

PHP SOURCE CODE

 

    1. Read All Incoming SMS

      <html>
      <head>
      <title>Read All INCOMING SMS</title>
      </head>
      <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
      <p><b> READ ALL INCOMING SMS </b></p>
      <?php
      /*
      ==========================================================================
      Copyright 2007 by MOBITEK System Sdn. Bhd.
      Acknowledgement: Mr. Mohd Najmi Bin Selamat (student of MULTIMEDIA UNIVERSITY MALAYSIA)
      has contributed to the development of this programme
      Terms and Conditions
      1. License condition: you are allowed to use, modify, distribute, this PHP code for free
      2. This source code is provided on "as-is" basis. No warranty nor support is provided on the use of the code
      3. BY USING THIS CODE, YOU ASSUME ALL THE RISK AND RESPONSIBILITY
      4. MOBITEK System Sdn. Bhd. EXPRESSLY DISCLAIMS ANY WARRANTIES
      5. MOBITEK System Sdn. Bhd. SHALL NOT BE LIABLE TO YOU OR ANYONE ELSE FOR ANY LOSS OR DAMAGES WHATSOEVER
      ==========================================================================
      */
      //the DSN is "SMSEngine5", please rename if your DSN is different
       //establish connection to Access database via ODBC
       $conn=odbc_connect('SMSEngine5','','');
       if (!$conn)
       {exit("Connection Failed:" . odbc_errormsg() );}
      //read all incoming SMS and display in a table
       $sql="SELECT Message, Mobile, DateTime, Status FROM Inbox ORDER BY DateTime";
       $rs=odbc_exec($conn,$sql);
       if (!$rs)
       {exit("Error in SQL");}
      //---------- display in table -----------------
       echo "<table><tr>";
       echo "<th>Message</th>";
       echo "<th>Mobile</th>";
       echo "<th>DateTime</th>";
       echo "<th>Status</th></tr>";
      while (odbc_fetch_row($rs))
       {
      $message=odbc_result($rs,"Message");
       $mobile=odbc_result($rs,"Mobile");
       $datetime=odbc_result($rs,"DateTime");
       $status=odbc_result($rs,"Status");
      echo "<tr><td>$message</td>";
       echo "<td>$mobile</td>";
       echo "<td>$datetime</td>";
       echo "<td>$status</td></tr>";
       }
      echo "</table>";
       //---------- display in table -----------------
      //close connection to database
       odbc_close($conn);
      ?>
      </body>
      </html>
    2. Read New SMS

      <html>
      <head>
      <title>Read SMS</title>
      </head>
      <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
      <p><b> READ NEW SMS </b></p>
      <?php
       /*
       ==========================================================================
       Copyright 2007 by MOBITEK System Sdn. Bhd.
      Acknowledgement: Mr. Mohd Najmi Bin Selamat (student of MULTIMEDIA UNIVERSITY MALAYSIA)
      has contributed to the development of this programme
      Terms and Conditions
       1. License condition: you are allowed to use, modify, distribute, this PHP code for free
       2. This source code is provided on "as-is" basis. No warranty nor support is provided on the      use of the code
       3. BY USING THIS CODE, YOU ASSUME ALL THE RISK AND RESPONSIBILITY
       4. MOBITEK System Sdn. Bhd. EXPRESSLY DISCLAIMS ANY WARRANTIES
       5. MOBITEK System Sdn. Bhd. SHALL NOT BE LIABLE TO YOU OR ANYONE ELSE FOR ANY LOSS OR DAMAGES     WHATSOEVER
       ==========================================================================
       */
      //the DSN is "SMSEngine5", please rename if your DSN is different
       //establish connection to Access database via ODBC
       $conn=odbc_connect('smsengine5','','');
       if (!$conn)
       {exit("Connection Failed:" . odbc_errormsg() );}
      //read new incoming SMS
       $sql="SELECT Message, Mobile, DateTime, Status FROM Inbox WHERE STATUS = 'New'";
       $rs=odbc_exec($conn,$sql);
       if (!$rs)
       {exit("Error in SQL");}
      //---------- display in table -----------------
       echo "<table><tr>";
       echo "<th>Message</th>";
       echo "<th>Mobile</th>";
       echo "<th>DateTime</th>";
       echo "<th>Status</th></tr>";
      while (odbc_fetch_row($rs))
       {
       $message=odbc_result($rs,"Message");
       $mobile=odbc_result($rs,"Mobile");
       $datetime=odbc_result($rs,"DateTime");
       $status=odbc_result($rs,"Status");
      echo "<tr><td>$message</td>";
       echo "<td>$mobile</td>";
       echo "<td>$datetime</td>";
       echo "<td>$status</td></tr>";
       }
      echo "</table>";
       //---------- display in table -----------------
      //change status from "New" to "Read"
       $sql = "UPDATE Inbox SET Status ='Read' WHERE Status = 'New' ";
       $rs2=odbc_exec($conn,$sql);
       if (!$rs2)
       {exit("Error in SQL");}
      //close connection to database
       odbc_close($conn);
      ?>
      </body>
      </html>
    3. Send SMS

      <html>
      <head>
      <title>Send SMS</title>
      </head>
      <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
      <p> <b>Send SMS </b><p>
      <?php
      /*
      ==========================================================================
      Copyright 2007 by MOBITEK System Sdn. Bhd.
      Acknowledgement: Mr. Mohd Najmi Bin Selamat (student of MULTIMEDIA UNIVERSITY MALAYSIA)
      has contributed to the development of this programme
      Terms and Conditions
      1. License condition: you are allowed to use, modify, distribute, this PHP code for free
      2. This source code is provided on "as-is" basis. No warranty nor support is provided on the use of the code
      3. BY USING THIS CODE, YOU ASSUME ALL THE RISK AND RESPONSIBILITY
      4. MOBITEK System Sdn. Bhd. EXPRESSLY DISCLAIMS ANY WARRANTIES
      5. MOBITEK System Sdn. Bhd. SHALL NOT BE LIABLE TO YOU OR ANYONE ELSE FOR ANY LOSS OR        DAMAGES WHATSOEVER
      ==========================================================================
      */
      //the DSN is "SMSEngine5", please rename if your DSN is different
      //establish connection to Access database via ODBC
       $conn = odbc_connect('SMSEngine5','','');
       if (!$conn)
       {exit("Connection Failed:" . odbc_errormsg() );}
      //queue outgoing SMS into Outbox table
       $sql="INSERT INTO Outbox (Message, Mobile, DateTimeQueue, SentStatus) VALUES ('$_POST[Message]','$_POST[Mobile]',date(),'P')";
       $rs=odbc_exec($conn, $sql);
      echo "Your message - '" ." ". $_REQUEST["Message"] ." ". "' to this phone number - " ." ". $_REQUEST["Mobile"] ." ". "is being queued. It will be send out in a moment.";
      //close connection to database
       odbc_close($conn);
      ?>
      </body>
      </html>
    4. Display All Outgoing SMS

      <html>
      <head>
      <title>DISPLAY All OUTGOING SMS</title>
      </head>
      <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
      <p><b>DISPLAY All OUTGOING SMS</b></p>
      <?php
      /*
      ==========================================================================
      Copyright 2007 by MOBITEK System Sdn. Bhd.
      Acknowledgement: Mr. Mohd Najmi Bin Selamat (student of MULTIMEDIA UNIVERSITY MALAYSIA)
      has contributed to the development of this programme
      Terms and Conditions
      1. License condition: you are allowed to use, modify, distribute, this PHP code for free
      2. This source code is provided on "as-is" basis. No warranty nor support is provided on the use of the code
      3. BY USING THIS CODE, YOU ASSUME ALL THE RISK AND RESPONSIBILITY
      4. MOBITEK System Sdn. Bhd. EXPRESSLY DISCLAIMS ANY WARRANTIES
      5. MOBITEK System Sdn. Bhd. SHALL NOT BE LIABLE TO YOU OR ANYONE ELSE FOR ANY LOSS OR        DAMAGES WHATSOEVER
      ==========================================================================
      */
      //the DSN is "SMSEngine5", please rename if your DSN is different
       //establish connection to Access database via ODBC
       $conn=odbc_connect('SMSEngine5','','');
       if (!$conn)
       {exit("Connection Failed:" . odbc_errormsg() );}
      //read all incoming SMS and display in a table
       $sql="SELECT Message, Mobile, DateTimeSent, SentStatus, DateTimeDeliver, DeliveryStatus FROM Outbox ORDER BY DateTimeSent";
       $rs=odbc_exec($conn,$sql);
       if (!$rs)
       {exit("Error in SQL");}
      //---------- display in table -----------------
       odbc_result_all($rs);
      //close connection to database
       odbc_close($conn);
      ?>
      </body>
      </html>

 

 

 

TERMS AND CONDITIONS ON THE USE OF THE PHP SOURCE CODE

 

Acknowledgement: Mr. Mohd Najmi Bin Selamat (student of MULTIMEDIA UNIVERSITY MALAYSIA) has contributed to the development of this source code and programme.

  1. This sample code is to be used with SMS Engine. SMS Engine is one of the development tool in MOBITEK SMS Gateway Development Kit.

  2. You are allowed to use, modify, distribute, this PHP code for free.

  3. This source code is provided on “as-is” basis. No warranty nor support is provided on the use of the code.

  4. BY USING THIS CODE, YOU ASSUME ALL THE RISK AND RESPONSIBILITY

  5. MOBITEK System Sdn. Bhd. EXPRESSLY DISCLAIMS ANY WARRANTIES

  6. MOBITEK System Sdn. Bhd. SHALL NOT BE LIABLE TO YOU OR ANYONE ELSE FOR ANY LOSS OR DAMAGES WHATSOEVER