Home » Documentation » SMS to Web server, SMS to HTTP

SMS to Web server

SMS Enabler can automatically forward incoming SMS text messages to a web server via HTTP, so those messages can be handled by a server-side script. The script can be written in any web programming language, such as PHP, ASP.NET and so forth.

In this chapter, you will find information to help you to create such scripts. You can also find PHP and ASP.NET sample scripts in the SMS Enabler package.

After creating a script and installing it on your web server, you must enable SMS-to-web-server forwarding and set your script URL in the Settings dialog box in the SMS to Webserver tab.

HTTP Request and Response

SMS Enabler uses HTTP POST requests to forward received SMS messages to a web server. The server must return 200 OK or 204 No Content status to indicate success. Any other status code is taken by SMS Enabler as a failure, and causes the program to retry the request. The retry timeout interval is defined in the settings; the default is 30 seconds.

The request content type is application/x-www-form-urlencoded. This is the same content type that HTML forms use to post data to a web server. Without going into too much detail, the application/x-www-form-urlencoded content type is a set of field names and their corresponding values, which are used by SMS Enabler to carry all SMS message information. You can easily retrieve field values by their names using almost any modern web programming language. See the code samples and field descriptions below.

Sending a Reply SMS from the Script

To enable replies from the script, you must set the source for the reply message text to HTTP response content in the Settings dialog box in the Reply SMS tab.

To send a reply SMS, your script should return it as plain text in the content of the HTTP response. The content length must be greater than 0, and the content type set to 'text/plain' or any other 'text/*' MIME type. The response status code must be 200 OK. If you are sending non-ASCII characters, it's important to set the correct character encoding.

In order to send a reply SMS message to a number other than the one from which the original message was received, you must to add a custom HTTP header named 'X-SMS-To' to the HTTP response in your script. The header's value must be set to the number to which the reply SMS message must be sent.

Code samples

PHP

/* Getting sender's phone number and message text */
$senderPhone = $_POST['sender'];
$messageText = $_POST['text'];
/* Sending a reply SMS. */
/* Setting the HTTP response content type and charset */

header('Content-Type: text/plain; charset=utf-8');
/* Comment the next line out if you do not want to send a reply */
echo 'Reply message text';

Download PHP sample script

ASP.NET (C#)

// Getting sender's phone number and message text
string senderPhone = Request.Form["sender"];
string messageText = Request.Form["text"];

Response.Clear();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
/* Sending a reply SMS.
Comment the next line out if you do not want to send a reply */

Response.Write("Reply message text");
/*The next line is necessary whether or not you are sending a reply*/
Response.End();

Download Visual Studio ASP.NET sample project

You can find complete PHP and ASP.NET example scripts in the SMS Enabler package.

Character encoding

All text values are converted to UTF-8 before encoding them to application/x-www-form-urlencoded.

Field descriptions:

Field nameDescription
senderSender phone number.
textSMS message text.
sctsSMS center time stamp, in UTC, expressed using "YYYY-MM-DD HH:MM:SS" format. You can consider this as the time when the sender sent the message.
tagTag value. You can define this in SMS Enabler's settings, and use it to pass additional information.
has_missing_partsThis field can be set to "yes" or "no".
"yes" - Indicates that an SMS message is a multipart message and not all of its parts have arrived (i.e., the message is incomplete).
"no" - Means the message is complete.
The maximum time period to wait for all parts to be received is defined in the program's settings.
smscSMS center number (not supported when SMS Enabler is connected to a Nokia phone).

Copyright © 2006-2011 Alexander Smirnov. All rights reserved.