<?php
<?php
include 'include/MyConnect2.php';
date_default_timezone_set('Asia/Bangkok');
$date = date('d-m-Y H:i:s');

//$fp = fopen('php://input','r');
//$rec5 = fgets($fp);
//fclose($fp);

$rec = file_get_contents("php://input");

$sendtmp = strpos($rec, "SMSP01");
$txid = substr($rec,$sendtmp+7,11);

$ser = strpos($rec, "messageid");
$mid = substr($rec,$ser+11,10);

        $request_file = "moreply.xml"; 
        $fh = fopen($request_file, 'r'); 
        $xml_data = fread($fh, filesize($request_file)); 
        fclose($fh); 

//$xml_data = file_get_contents("moreply.xml");
$str1=str_replace("aaaaaa", $txid,$xml_data);
$str=str_replace("bbbbbb", $mid,$str1);

$postdata = file_get_contents("moreply.html");
$head=str_replace("cccccc", strlen($xml_data),$postdata);
//$host = $_SERVER['HTTP_HOST'];
$addr = $_SERVER['REMOTE_ADDR'];
$rmport = $_SERVER['REMOTE_PORT'];

        $headers = array( 
            "HTTP/1.1 200 OK", 
	    "Content-length: ".strlen($str),             
            "Connection: Close", 
	    "Content-type: text/xml"           
        ); 


$url = "http://119.46.174.148:55000";

        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
        
        // Apply the XML to our curl call 
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $str); 

        $data = curl_exec($ch); 


  
//include 'sendmt_ok.php';
//mysqli_query($MyConnect, "INSERT INTO tbl_receiver_tmh (receive,logtime) VALUES ('$xml_data','$date')");
mysqli_query($MyConnect, "INSERT INTO tbl_receiver_tmh2 (receive,logtime) VALUES ('$rec5','$date')"); 

?>

?>