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 (http://www.wampserver.com/en/download.php) to install PHP and Apache. Please make sure you are downloading the WAMP server 32 bit NOT 64 bit.

 

Install Apache and PHP using WAMP

  1. Run the “wampserver2.5.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.PHPSMS-001
  3. Change the default destination folder for SMS Engine by click on Browse button.PHPSMS-002

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

 

Configure ODBC

    1.  Click Start, click Control Panel, go to Administrative Tools and click ODBC Data Sources (32-bit).PHPSMS-005
    2. Choose System DSN tab, then click on Add button.PHPSMS-006
    3. Find the Microsoft Access Driver(*.mdb, *.accdb) then click Finish button.PHPSMS-007
    4. Type “SMSEngine5”into a field provided then click on Select button.PHPSMS-008
    5. Locate the directories of the database in SMS Engine5.PHPSMS-009
    6. After found it, just click on OK button.PHPSMS-010
    7. The directory of the database SMSEngine5 will be appear. Then click on OK button.PHPSMS-011
    8. After completed, click on OK button.PHPSMS-012

 

 

Installing PHP code

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

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

 

RUN THE WAMPSERVER

  1. Click start and search for your wamp server. Start wampserver2.5.
    PHPSMS-015
  2. Find your wampserver at downside, right hand side. Make sure the ‘W’ is turned into green colour means it it online.PHPSMS-016

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

  3. Test the Port first to make sure the port is not being used with other applications.
    • Click at wamp logo
    • Click at Apache
    • Click at Service
    • Test Port 80PHPSMS-018
    • It display like this:
      PHPSMS-019Note: If port 80 is being used by another applications such as skype and others, you must change the port at “httpd.conf”. Refer below images step by step.

      • Click at wamp logo

      • Click at Apache

      • Click at “httpd.conf”PHPSMS-020

    • It display like this:
      PHPSMS-021
    • Change all the 80 to any port. e.g:8080. It should be like this:
      PHPSMS-022
    • Save the edited one.
  4. Run the local host
    • Click at wamp logo
    • Click at Localhost
      PHPSMS-023
  5. Your local host will appear on web browser like below.
    PHPSMS-024
  6. Change the address and click enter in order to go to the PHPSMS.
    PHPSMS-025
  7. Now, you can see all the 4 links which is linked to the 4 php code that you already copy in C:wampwwwPHPSMS
    PHPSMS-026

 

RUN THE SMS ENGINE

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

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

 

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