|
Advanced Services - SMS Connectivity PHP Sample application using HTTP to send an EMS message |
![]() |
The following sample application written in PHP sends an EMS 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 EMS 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 = 'submitsm';
$client_id = '<your client_id>';
$destaddr = '<some fully-qualified MSISDN>';
$shortmessage = '7C0C7A00424547494E3A494D454C4F44590D0A56455253494F4E3A312E320'
. 'D0A464F524D41543A434C415353312E300D0A4D454C4F44593A6433236333'
. '6433236333643372326433236333643365332366336533236633673361332'
. '36733613323673361337232613323673361330D0A454E443A494D454C4F44'
. '590D0A';
$secret = '<your secret>';
// Compute the MD5 hash (digest)
$hash = md5($secret . $shortmessage . $destaddr);
// Build and encode the URL.
$url = "http://$host:$port/$action/?client_id=$client_id&destaddr=$destaddr&dcs=245"
. "&esm=64&shortmessage=$shortmessage&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>
ems_http_example.php
Copyright © Hay Systems Ltd 2009
Owner: support@haysystems.com 20 September 2004