Send SMS messages from PHP

/Send messages from a web pages/

The Ozeki SMS Server enables you to send and receive SMS messages from PHP scripts. The SMS Server and the PHP script can be located on two different computers. This means that more than one script can send messages at the same time with only one SMS Server (Figure 1.).

sending messages with ozeki sms server
Figure 1 - Sending messages with ozeki sms server

To send messages from PHP you need to use the file sendsms.php. This file is included in the SMS Server software package. It provides functions to place the messages onto the SMS Servers queue for sending and to get the incoming messages. Take a look at the following example:

Sending SMS messages

<?php
include("sendsms.php");
$credits = sms_connect('192.168.0.1','9010','myAccount');
if ($credits>0) {
   sms_send('+36201234567','Hello World!');
}

sms_disconnect();
?>
	

Code 1 - Example of sending SMS messages from PHP

Download: php-client.zip

Receiving SMS messages


<?php

$OZEKISMS="/var/sms";

function sms_send($tel,$fromtel,$msg)
{
 global $OZEKISMS;
 $fn="send".time();
 $handle = fopen ($OZEKISMS."/folders/outbox/".$fn.".lock", "w");
 if (!$handle) {
 # hiba
 print "Write error. $OZEKISMS/folders/outbox/ is not writeable!\n";
 return false;
 } # end if
 $handle = fopen ($OZEKISMS."/folders/outbox/".$fn, "w");
 if (!$handle) {
 # hiba
 print "Write error. $OZEKISMS/folders/outbox/ is not writeable!\n";
 return false;
 } # end if
 if (!fwrite($handle,$fromtel."\n")) {
 print "Cannot write to file ($fn)";
 return false;
 }
 if (!fwrite($handle,$tel."\n")) {
 print "Cannot write to file ($fn)";
 return false;
 }
 if (!fwrite($handle,$msg."\n")) {
 print "Cannot write to file ($fn)";
 return false;
 }
 fclose($handle);
 unlink($OZEKISMS."/folders/outbox/".$fn.".lock");
 return true;
} # end function

if(sms_send("+36305301903","Hello World!")) {
 print "sms is under delivery.";
} else {
 print "Error.";
}

?>
	

Code 2 - Alternate example of sending SMS messages from PHP using files

Receiving SMS messages

<?
include("sendsms.php");
$credits = sms_connect('192.168.0.1','9010','myLogin');

echo "Receiving messages...
"; $inbox = sms_receive(); echo "$inbox"; sms_disconnect(); ?>

Code 3 - Example of receiving SMS messages from PHP

Related pages: