Send SMS from PHP Script

Posted by on Oct 17, 2008 in Support Blog

Topic Keywords: , , ,

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 —

ASP Examples —

Command Line Script Examples —

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

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

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:

For comments and further discussion, please click here to visit the NowSMS Technical Forums (Discussion Board)...

7 Responses to “Send SMS from PHP Script”

  1. 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.

  2. Bryce Norwood says:


    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:


  3. please help me,
    I want to send sms to multiple numbers. Php script?


  4. An updated version of this script which supports additional NowSMS URL parameters (such as for specifying an explicit outbound SMSC route or a sender address) can be found at

  5. HI there,
    SO ive got the form working but i want to add default message at the end of the message.
    so the user types in the message and when the SMS is sent it should also have another text after the users typed message. how do i do that?

    • Either use JavaScript in your form to append text on submit …

      Or hard code the added text within the PHP script. An example of adding it to the PHP script follows.

      Change this:

      fwrite($fp, “GET /?Phone=” . rawurlencode($phoneNoRecip) . “&Text=” . rawurlencode($msgText) . ” HTTP/1.0\n”);

      to this:

      $addText = ” (Powered by Me)”;

      fwrite($fp, “GET /?Phone=” . rawurlencode($phoneNoRecip) . “&Text=” . rawurlencode($msgText) . rawurlencode($addText) . ” HTTP/1.0\n”);


  1. Using PHP Scripts to Extend NowSMS | NowSMS - [...] back to the SMS message, your script can issue new requests back to NowSMS to send messages (see Send…