The following code is a PHP v5 example of sending a message using XML.
<?php/*** Sample SMS API XML Interface example in PHP* Copyright Mediaburst 2009-2010** IMPORTANT NOTE:* This script is a brief example and should not be used in* a live environment.* This script is provided without warranty and Mediaburst* do not offer any support in the use of this example.*/// Turning on track_errors allows us to see details on HTTP errorsini_set("track_errors", 1);// Set Debug to 1 to output request and response XML$debug = 1;// Account Parameters$server = 'http://sms.message-platform.com/xml/send.aspx';$username = 'My_User';$password = 'My_Pass';$content = 'Mediaburst XML API Test - PHP Example';/*** Numbers to send to* Normally this would come from your database/application*/$numbers = array('447000000001','447000000002','447000000abc');// Build the XML request to send$req_doc = new DOMDocument('1.0', 'UTF-8');$root = $req_doc->createElement('Message');$req_doc->appendChild($root);$root->appendChild($req_doc->createElement('Username', $username));$root->appendChild($req_doc->createElement('Password', $password));// Create an SMS Element for each recipientforeach($numbers as $number){$sms_node = $req_doc->createElement('SMS');$sms_node->appendChild($req_doc->createElement('To', $number));$sms_node->appendChild($req_doc->createElement('Content',
$content));$root->appendChild($sms_node);}$req_xml = $req_doc->saveXML();if($debug) print("Request:\n$req_xml\n");$resp_xml = sendToHost($server,$req_xml);if($debug) print("Response:\n$resp_xml\n");$resp_doc = DOMDocument::loadXML($resp_xml);$err_no = null;$err_desc = null;foreach($resp_doc->documentElement->childNodes AS $doc_child){switch($doc_child->nodeName){case "SMS_Resp":$to = null;$msg_id = null;$sms_err_no = null;$sms_err_desc = null;foreach($doc_child->childNodes AS $resp_node){switch($resp_node->nodeName){case "To":$to = $resp_node->nodeValue;break;case "MessageID":$msg_id = $resp_node->nodeValue;break;case "ErrNo":$sms_err_no = $resp_node->nodeValue;break;case "ErrDesc":$sms_err_desc = $resp_node->nodeValue;break;}}if(isset($sms_err_no))print "To: $to Error $sms_err_no: $sms_err_desc\n";elseprint "To: $to ID: $msg_id\n";break;case "ErrNo":$err_no = $doc_child->nodeValue;break;case "ErrDesc":$err_desc = $doc_child->nodeValue;break;}}if(isset($err_no))print "Error in request.\nError Number: $err_no Description:
$err_desc\n";/** Function to perform the HTTP POST to Mediaburst API Server* PHP Doesn't have convenient HTTP functions in many default installs*/function sendToHost($url,$data){$params = array('http' => array('method' => 'POST','header' => 'Content-Type: text/xml\r\n','content' => $data));$ctx = stream_context_create($params);$fp = @fopen($url, 'rb', false, $ctx);if (!$fp) {throw new Exception("Problem with $url,
$php_errormsg");}$response = @stream_get_contents($fp);if ($response === false) {throw new Exception("Problem reading data from $url,
$php_errormsg");}return $response;}?>
<?php
/**
* Sample SMS API XML Interface example in PHP
* Copyright Mediaburst 2009-2010
*
* IMPORTANT NOTE:
* This script is a brief example and should not be used in
* a live environment.
* This script is provided without warranty and Mediaburst
* do not offer any support in the use of this example.
*/
// Turning on track_errors allows us to see details on HTTP errors
ini_set("track_errors", 1);
// Set Debug to 1 to output request and response XML
$debug = 1;
// Account Parameters
$server = 'http://sms.message-platform.com/xml/send.aspx';
$username = 'My_User';
$password = 'My_Pass';
$content = 'Mediaburst XML API Test - PHP Example';
/**
* Numbers to send to
* Normally this would come from your database/application
*/
$numbers = array('447000000001','447000000002','447000000abc');
// Build the XML request to send
$req_doc = new DOMDocument('1.0', 'UTF-8');
$root = $req_doc->createElement('Message');
$req_doc->appendChild($root);
$root->appendChild($req_doc->createElement('Username', $username));
$root->appendChild($req_doc->createElement('Password', $password));
// Create an SMS Element for each recipient
foreach($numbers as $number)
{
$sms_node = $req_doc->createElement('SMS');
$sms_node->appendChild($req_doc->createElement('To', $number));
$sms_node->appendChild($req_doc->createElement('Content', $content));
$root->appendChild($sms_node);
}
$req_xml = $req_doc->saveXML();
if($debug) print("Request:\n$req_xml\n");
$resp_xml = sendToHost($server,$req_xml);
if($debug) print("Response:\n$resp_xml\n");
$resp_doc = DOMDocument::loadXML($resp_xml);
$err_no = null;
$err_desc = null;
foreach($resp_doc->documentElement->childNodes AS $doc_child)
{
switch($doc_child->nodeName)
{
case "SMS_Resp":
$to = null;
$msg_id = null;
$sms_err_no = null;
$sms_err_desc = null;
foreach($doc_child->childNodes AS $resp_node)
{
switch($resp_node->nodeName)
{
case "To":
$to = $resp_node->nodeValue;
break;
case "MessageID":
$msg_id = $resp_node->nodeValue;
break;
case "ErrNo":
$sms_err_no = $resp_node->nodeValue;
break;
case "ErrDesc":
$sms_err_desc = $resp_node->nodeValue;
break;
}
}
if(isset($sms_err_no))
print "To: $to Error $sms_err_no: $sms_err_desc\n";
else
print "To: $to ID: $msg_id\n";
break;
case "ErrNo":
$err_no = $doc_child->nodeValue;
break;
case "ErrDesc":
$err_desc = $doc_child->nodeValue;
break;
}
}
if(isset($err_no))
print "Error in request.\nError Number: $err_no Description: $err_desc\n";
/*
* Function to perform the HTTP POST to Mediaburst API Server
* PHP Doesn't have convenient HTTP functions in many default installs
*/
function sendToHost($url,$data)
{
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: text/xml\r\n',
'content' => $data
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
You might find our Mobile site useful.