ActiveXperts SMS Messaging Server

Quicklinks

Create an SMS message using the SMS Messaging Server API - PHP

SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:

  • Mobile users query a database; results are sent back via SMS or e-mail;
  • Mobile users receive important information via SMS or e-mail while they are away from the office;
  • Stock prices are sent automatically via SMS and/or e-mail, daily;
  • Remote workers can update their worksheet from a remote location trough SMS;
  • ICT administrators restart/reboot servers and/or daemons from remote by SMS;
  • Setup an SMS voting system, supporting SMS and/or e-mail;
  • Etc.

SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into your own projects.


Introduction

In this example we are going to create a PHP sample page to create an SMS using the ActiveXperts SMS Messaging Server API. The SMS Messaging Server service will send the message you created in the database.

Step 1: Download and install SMS Messaging Server

Download ActiveXperts SMS Messaging Server from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create the SMS Messaging Server PHP objects

Create a new PHP script called index.php in the root directory of IIS or Apache, using your favorite editor. On top of the PHP code, insert the following lines to declare and create the SMS Messaging Server API objects:

$objConstants = new COM ( "AxMmServer.Constants", NULL, CP_UTF8 ); $objMessageDB = new COM ( "AxMmServer.MessageDB", NULL, CP_UTF8 );

Step 3: Create the SMS message

The following code will create an empty record in the database where the message will be stored.

// Create a new message $objMessage = $objMessageDB->Create (); if ( $objMessageDB->LastError <> 0 ) { $ErrorDes = $objMessageDB->GetErrorDescription ( $objMessageDB->LastError ); die ( $ErrorDes ); }

Step 4: Set the message settings

The following code wil setup the settings for the message.

// Set the message type according to the users input if (strstr($_POST[Type], "SMS")) $objMessage->TypeID = $objConstants->MESSAGETYPE_SMS; else $objMessage->TypeID = $objConstants->MESSAGETYPE_EMAIL; // Set the message charset according to the users input if (strstr($_POST[Charset], "Unicode")) $objMessage->CharsetID = $objConstants->MESSAGECHARSET_UNICODE; else $objMessage->CharsetID = $objConstants->MESSAGECHARSET_CHANNEL_DEFAULT; $objMessage->ChannelID = intval ( $_POST[Channel] ); $objMessage->ToAddress = $_POST[To]; $objMessage->Body = $_POST[Body]; // Direction and status will always be the same. $objMessage->DirectionID = $objConstants->MESSAGEDIRECTION_OUT; $objMessage->StatusID = $objConstants->MESSAGESTATUS_PENDING;

Step 5: Save an SMS message

The following PHP code shows how to save an SMS message:

// Save the message to the message database. This way the Messaging server will // pick it up and try to send it. $objMessageDB->Save ( $objMessage ); if ( $objMessageDB->LastError <> 0 ) { $ErrorDes = $objMessageDB->GetErrorDescription ( $objMessageDB->LastError ); die ( $ErrorDes ); }

Appendix: Full source code

Following you can find the full source code, which is also included in SMS Messaging Server:

<html> <head> <META HTTP-EQUIV="CONTENT-Type" CONTENT="text/html; charset="UTF-8"; > <title>ActiveXperts SMS Messaging Server PHP Sample</title> <style> input, select { width:150px; } </style> </head> <body> <?php // If any type of message was posted to this page, try to send it if ($_POST[Type]) { // Create COM objects (with Unicode(UTF8) codepage) $objConstants = new COM ( "AxMmServer.Constants", NULL, CP_UTF8 ); $objMessageDB = new COM ( "AxMmServer.MessageDB", NULL, CP_UTF8 ); // Open message database $objMessageDB->Open (); if ( $objMessageDB->LastError <> 0 ) { // Display error message and exit $ErrorDes = $objMessageDB->GetErrorDescription ( $objMessageDB->LastError ); die ( $ErrorDes ); } // Create a new message $objMessage = $objMessageDB->Create (); if ( $objMessageDB->LastError <> 0 ) { $ErrorDes = $objMessageDB->GetErrorDescription ( $objMessageDB->LastError ); die ( $ErrorDes ); } // Set the message type according to the users input if (strstr($_POST[Type], "SMS")) $objMessage->TypeID = $objConstants->MESSAGETYPE_SMS; else $objMessage->TypeID = $objConstants->MESSAGETYPE_EMAIL; // Set the message charset according to the users input if (strstr($_POST[Charset], "Unicode")) $objMessage->CharsetID = $objConstants->MESSAGECHARSET_UNICODE; else $objMessage->CharsetID = $objConstants->MESSAGECHARSET_CHANNEL_DEFAULT; $objMessage->ChannelID = intval ( $_POST[Channel] ); $objMessage->ToAddress = $_POST[To]; $objMessage->Body = $_POST[Body]; // Direction and status will always be the same. $objMessage->DirectionID = $objConstants->MESSAGEDIRECTION_OUT; $objMessage->StatusID = $objConstants->MESSAGESTATUS_PENDING; // Save the message to the message database. This way the Messaging server will // pick it up and try to send it. $objMessageDB->Save ( $objMessage ); if ( $objMessageDB->LastError <> 0 ) { $ErrorDes = $objMessageDB->GetErrorDescription ( $objMessageDB->LastError ); die ( $ErrorDes ); } // Close message database $objMessageDB->Close (); // Inform the user of our success and display a welcome header. ?> <h3>Message succesfully added to queue !</h3> <h2>Send another message using PHP</h2> <?php } else { // If no message type was posted, display a welcome header ?> <h2>Send a message using PHP</h2> <?php } ?> <form action="index.php" method="post"> <table width="700"> <tr> <td>Type:</td><td> <select type="text" name="Type" > <option <?php if ( $_POST[Type] == "SMS" ) { echo "selected"; } ?> >SMS</option> <option <?php if ( $_POST[Type] == "E-mail" ) { echo "selected"; } ?> >E-mail</option> </select> </td> </tr> <tr> <td>Charset:</td> <td> <select type="text" name="Charset" > <option <?php if ( $_POST[Charset] == "Plain Text" ) { echo "selected"; } ?> >Plain Text</option> <option <?php if ( $_POST[Charset] == "Unicode" ) { echo "selected"; } ?> >Unicode</option> </select> </td> </tr> <tr> <td>Channel:</td> <td> <input type="text" name="Channel" value=" <?php if (!empty($_POST[Channel])) { echo ($_POST[Channel]); } ?>" /> Use '0' to select the first available channel. </td> </tr> <tr> <td>To:</td> <td> <input type="text" name="To" value="<?php if (!empty($_POST[To])) { echo ($_POST[To]); } ?>" /> E-mail adress or <a href="http://www.activexperts.com/support/sms-messaging-server/index.asp?kb=Q8000020" target="_blank">phone number</a> </td> </tr> <tr> <td valign="top">Body:</td> <td><textarea name="Body" rows="3" cols="50" > <?php if (!empty($_POST[Body])) { echo ($_POST[Body]); } else { echo "ActiveXperts SMS Messaging Server test message"; } ?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" value="Send message"></td> </tr> </table> </form> </body> </html>

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-messaging-server. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The SMS Messaging Server project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.