It is a relatively simple process to define a 2-way command that returns a text response to the message sender. The “2-Way” page of the NowSMS configuration dialog allows you to define commands that are executed when an SMS message is received. The receipt of an inbound SMS message by the gateway can cause an executable command to be executed, or the gateway can connect to an HTTP URL to run a script on a separate web server. If “Command returns response text” is set for the command, it is simple for the command to return a text response back to the sender of the SMS. In the case of an HTTP URL, the HTTP URL can return a simple text response with a MIME type for the response set as “text/plain”, and the gateway will automatically send this text as a response back to the sender of the SMS.
In the example shown in the screen shot above, the receipt of a text SMS message causes the gateway to connect to the HTTP URL:
http://192.168.1.102/cgi-bin/sms.cgi?Sender=@@Sender@@&Text=@@FullSMS@@
When a message is processed, the “@@Sender@@” value is replaced with the phone number of the sender of the received message, and @@FullSMS@@ contains the complete text of the received message.
What if an HTTP script wants to return a response back to the sender that is a non-text SMS format, such as WAP OTA settings, a Nokia smart messaging message, or even an MMS message?
The HTTP script could always include its own processing logic to spawn a command that issues a request back to the NowSMS gateway, but this can be difficult. An alternative approach is for the HTTP response to return a “redirect” response, where the redirect URL is a URL pointer back to the NowSMS gateway, for example http://127.0.0.1:8800/?PhoneNumber=%2b12125551212&… (If you want to be able to test your HTTP script by executing it from a web browser, you will need to substitute the real IP address of your NowSMS server for the 127.0.0.1 address.)
If your NowSMS server requires authentication, a username and password can be included in the redirect response using the URL format http://user:password@server.name/path.
Any URL that would work when sent directly to the NowSMS server can be returned as a “redirect” response. If a script will be returning a “redirect” response, it is important that “Command returns response text” is NOT checked for the command on the “2-Way” configuration dialog. This is because a redirect response simply instructs the HTTP client to retrieve a different URL. The NowSMS gateway will not return the actual response from that URL request to the client.
An HTTP redirect response is an HTTP 302 response, with the redirect URL included in the “Location:” header, for example:
HTTP/1.0 302 Redirect
Location: http://127.0.0.1:8800/?PhoneNumber=…
<blank line>
Most scripting languages have built-in support for returning a redirect response. For example, in an ASP script, Response.Redirect (“http://127.0.0.1:8800/?PhoneNumber=…) is used to send a redirect response. Other scripting languages have similar support.
Related pages:
- 2-way SMS: Multiple operators with the same shortcode This configuration issue comes up quite a bit. Let’s say that you are connecting directly to multiple mobile operators, and...
- 2-Way SMS Support Automatic SMS Reply and More … The “2-Way” configuration dialog contains settings relevant to the creation of 2-way applications that...
- Send SMS from Command Line A command line interface can sometimes be useful for quick sending of an SMS message from another application. A message...
- Send SMS Text Message with Java The following example Java class, sendsms, can be used to send an SMS text message via NowSMS from Java. This...
- Using PHP Scripts to Extend NowSMS PHP scripts are a great tool for integrating NowSMS into another application environment, or extending the functionality of NowSMS. PHP...
- 2-way SMS Command Speed and Performance (updated) Before I get to the speed/performance issue that I want to highlight, I’ll review some of the basics of 2-way...
- USSD and NowSMS, revisited There seems to be a lot of renewed interest in USSD applications these days. SMPP is very widely used as...
- Send SMS from PHP Script Over the coming weeks, I’m planning to collect various PHP, ASP and other script examples to provide some examples of...
- NowSMS Group Text Messaging The NowSMS Group Text feature is designed to facilitate group communications over SMS. At it’s core, it’s about sending a...
- Send SMS from Java (or JSP) A Java example for sending SMS messages via NowSMS has been posted at the following link: http://www.nowsms.com/download/sendsms.java.txt The sendsms class...
Topic Category: 2-way SMS
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...
2 Responses to “2-Way SMS Returning a Non-Text Response”


Click here to download a free trial version of NowSMS & MMS Gateway, NowSMS Lite or NowWAP Gateway.
Learn more about NowSMS Lite.
Hi i really need help pleas for my fyp.
i am developing a system that sends and receives sms.
now i can send and receive the sms but the problem is when i receive an sms, there is infinite loop that inserted the sms into the inbox table in mysql database. i am using php language.
this the last part of the code:
}
else
$sms=”Sorry!+you+have+to+register+first+before+you+use+our+service”;
$sql = “INSERT INTO inbox (sender_mobile, message_content, message_status, message_date) VALUES (‘$sender’, ‘$text’, ‘$mess_status’, ‘$mess_date’)” ;
$res=mysql_query($sql);
if($res){
header(“Location:http://127.0.0.1:8800/?PhoneNumber=$sender&Text=$sms“);
die();}
I’d suggest that you post your question with more detail in our discussion forum at http://www.nowsms.com/messages
To understand your problem, we would probably need to see your SMSDEBUG.LOG. This would give us a better idea of what commands are being executed, and how your system is configured, so that we could tell you how to fix the loop.
Head over to http://www.nowsms.com/messages and start a new thread.