You are here: Home > Download > PHP code

Post XML (with PHP code)

    (get source)
This is a sample application that demonstrates how to send a message through TeleMessage's xml interface from your PHP code. The application posts XML (that represent a message). The response includes message-id and message-key for tracing message delivery.

Note:
  1. PHP must be run with curl extension. For more information, visit http://www.php.net/manual/en/ref.curl.php
  2. You can parse XML by using DOM extension in PHP5 (http://www.php.net/manual/en/ref.dom.php) and DOMxml extension in PHP4 (http://www.php.net/manual/en/ref.domxml.php).


  function sendToTeleMessage($xmlstring){

  //creating header for http post request
$myHeader = array(
   "MIME-Version: 1.0",
   "Content-type: text/xml; charset=utf-8"
);
//creating and initiating curl
$ch = curl_init();
//setting curl/http headers
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xmlstring);
curl_setopt($ch, CURLOPT_URL," http://xml.telemessage.com/partners/xmlMessage.jsp ");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $myHeader);
//executing http request and getting response. $postResult will contain response xml from TeleMessage.
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
   return null;
   /*
   * for PHP5 you can throw Exception:
   * throw new Exception("Error while sending");
   */

}
curl_close($ch);

return $postResult;
  }