Advanced Services - SMS Connectivity

PHP Sample application using HTTP to send an SMS text message

HSL Mobile Messaging

The following sample application written in PHP sends an SMS text message to a single mobile telephone. The application uses HTTP to communicate with HSL's systems. To send to more than one mobile telephone at a time, separate each mobile number in the destaddr field by a comma (e.g. "447968000111,447720000111,3378100100").

<html>
<head>
    <title>Simple PHP example of text via the HSL HTTP interface</title>
</head>
<body>

<?php

// These variables fill out the various parts described in the interface
// specification
$host = 'sms.haysystems.com';
$port = '80';
$action = 'sendtxt';
$client_id = '<your client_id>';
$text = 'this is a test message';
$destaddr = '<some fully-qualified MSISDN>';
$secret = '<your secret>';

// Compute the MD5 hash (digest)
$hash = md5($secret . $text . $destaddr);

// Build and encode the URL.
// Note we are careful to URL-encode the message content as it is the only part
// of the URL likely to contain reserved characters.
$url = "http://$host:$port/$action/?client_id=$client_id&text="
       . urlencode($text) . "&destaddr=$destaddr&key=$hash";

// Make the HTTP call (you could use CURL on PHP 4+) we nab the content that
// readfile would normally output directly with the ob_start, ob_get_contents
// and ob_end_clean calls.
ob_start();
$result = @readfile($url);
$data = ob_get_contents();
ob_end_clean();

// Examine the results
if($result === false) {
    echo '<p>Could not make HTTP request; is the URL correct?</p>';
    echo "<p>$url</p>";

} else {
    echo "<p>Submission result: $data</p>";
}

?>

</body>
</html>

simple_http_example.php


Copyright © Hay Systems Ltd 2009

Owner: support@haysystems.com 20 September 2004

Sample code link | Developers section link