<?php
 
 
       
                $writer = new XMLWriter();
 
                $writer->openMemory();
                $writer->startDocument('1.0', 'UTF-8');
                $writer->startElementNS(
                                "soap12",
                                'Envelope',
                                'https://schemas.xmlsoap.org/soap/envelope/'
                );
                $writer->writeAttributeNs(
                                'xmlns',
                                'xsi',
                                null,
                                "https://www.w3.org/2001/XMLSchema-instance");
                $writer->writeAttributeNs(
                                'xmlns',
                                'xsd',
                                null,
                                "https://www.w3.org/2001/XMLSchema");
                $writer->startElementNs('soap12','Body',NULL);
                $writer->startElementNs(null,'SendSingleSmsMessage',"https://messagingsystem.co.il/");
                $writer->startElement('oLogin');
                    $writer->writeElement('UserName','account username');
                    $writer->writeElement('Password','account password');
                    $writer->endElement();// end oLogin
                $writer->writeElement('iUserID','account user id');
                $writer->writeElement('sMessageBody','enter your message');
                $writer->writeElement('sToPhone','receiver number');
                
                $writer->writeElement('sFromName','senders name');
 
 
                $writer->endElement();// end SendSingleSmsMessage
                $writer->endElement();// end soap12:body
 
                $writer->endElement();
                $writer->endDocument();
                $echo = $writer->outputMemory(true);
                // echo $echo;
                $headers = array(
                                'Cache-Control: no-cache',
                                'Pragma: no-cache',
                                'Content-length: ' . strlen($echo),
                                'Content-Type: text/xml; charset=utf-8',
        'SOAPAction: "https://messagingsystem.co.il/SendSingleSmsMessage"',
        );
                $cr = curl_init();
    curl_setopt($cr, CURLOPT_URL, 'https://heb.mesereser.com/Services/Services.asmx');
    curl_setopt($cr, CURLOPT_CONNECTTIMEOUT, 10);
                curl_setopt($cr, CURLOPT_TIMEOUT,        10);
                curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($cr, CURLOPT_POST, 1);
                curl_setopt($cr, CURLOPT_POSTFIELDS, $echo);
                curl_setopt($cr, CURLOPT_HTTPHEADER, $headers);
 
                $result = curl_exec($cr);
                $error = curl_error($cr);
                curl_close($cr);
 
                if (!empty($error)) {
                                return $error;
                } else {
                                //keeping it simple - throw away all the data that can be thrown, to avoid SimpleXMLElement error
                                $result = str_replace(array("<?xml version=\"1.0\" encoding=\"utf-8\"?>",'xmlns:soap="https://www.w3.org/2003/05/soap-envelope"','xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"','xmlns:xsd="https://www.w3.org/2001/XMLSchema"','xmlns="https://messagingsystem.co.il/"'), '', $result);
// soap:Envelope
                                $result = str_replace('soap:Envelope', 'root', $result);
                                $result = str_replace('soap:Body', 'Body', $result);
 echo $result;
                                
                }
 
 
?>
