Friday, 17 October 2008

NowSMS PHP Example: Send SMS Text Message

Over the coming weeks, I'm planning to collect various PHP, ASP and other script examples to provide some examples of how to interface with NowSMS from those environments.

The following links should provide all of the relevant postings, assuming that I follow-up with this task as planned.

PHP Examples -- http://blog.nowsms.com/search/label/PHP

ASP Examples -- http://blog.nowsms.com/search/label/ASP

Command Line Script Examples -- http://blog.nowsms.com/search/label/command%20line%20interface

We'll start with the simplest of examples, sending an SMS text message from a PHP script.
It was almost five years ago that we posted an example PHP script for this task on our discussion board at http://www.nowsms.com/discus/messages/1/867.html.

Below I've included basically the same five year old script, but I've added some minor comments for further clarification.

The SendSMS function is the important part of the example. This is the function that needs to be included in your PHP script. You call this function, specifying the host name or IP address and port number of the NowSMS server, along with a username and password for an "SMS Users" account on the NowSMS server, plus the recipient phone number and text of the SMS message.

The SendSMS function uses these parameters to build a URL for connecting to the NowSMS server. This function could be easily modified to support sending other types of messages by modifying the URL that the function creates. For additional information on NowSMS URL parameters, see http://www.nowsms.com/documentation/ProductDocumentation/sending_messages/url_parameters_for_sending_messages.htm.

Following the SendSMS function, we show two examples of how this function might be called from within a PHP script.

The first example shows hard coded parameters being passed to the SendSMS function.

The second example shows how a web form could post to the PHP script. The PHP script parses the variables received from the web form, and passes those variables to the SendSMS function to trigger NowSMS to send a message.

2 comments:

Anonymous said...

I try NowSMS, seems to good for my purpose building 2 way sms server.

But i wonder how can i handle voice call to automatically dropped when GSM number called by other party (i use dedicated PCMCIA modem, sierra aircard 875).

I can't use manual AT command to do that since port already used by NowSMS.

Any idea?
Or maybe a feature request to automatically reject incoming voice call on NowSms server.

Bryce Norwood said...

Hi,

Apologies for the delay in response. Our comment notification setup for blogger was not working.

I believe you also posted your query over on our discussion forum, where we responded to it at:

http://www.nowsms.com/discus/messages/1/24457.html

-bn