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://www.nowsms.com/tag/php
ASP Examples — http://www.nowsms.com/tag/asp
Command Line Script Examples — http://www.nowsms.com/tag/command-line-interface
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/doc/submitting-sms-messages/url-parameters.
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.
The script detailed below can be downloaded at the following link: http://www.nowsms.com/download/sendsms-php.txt.
For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...