<?php
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/mysql.inc");
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/pgsql.inc");
	require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sendmail.inc");

//	$handle = fopen("log.txt", "a+");

	$ndate = "[".date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])."]";

//	fwrite($handle, $ndate."Called ADDR : ".$_SERVER["REMOTE_ADDR"]."\r\n");

	$mseg = $_REQUEST['msg'];
	
	$body_in = $_REQUEST['body'];
	$msg = "[".$_REQUEST['host'].":".$_REQUEST['owner']."]::".$mseg;

	$to_mails = $_REQUEST['mailto'];
	
	// CHG 2010-06-01 huibong netomi.co.kr domain expired & new domain information set.
	// CHG 2010-06-03 huibong from & sender is equal.. google mail not tranfer...icsaler@solbox.com to svc1@solbox.com changed..
	//$from_mail = "icsalert@netomi.co.kr";
	//$from_mail = "icsalert@solbox.com";
	$from_mail = "svc1@solbox.com";
	
	$body = trim(htmlBody($body_in));

	//echo("BODY $body");

	//echo("MSG $msg TO_MAILS $to_mails\n");
	$errmsg="";
    //fwrite($handle, $ndate."body_in : ".$body_in."\r\n");
try {
	$to_mail = explode(",", $to_mails);
	$cnt = count($to_mail);
	for($i=0; $i < $cnt; $i++) {	
		$sendmail = new sendmail("127.0.0.1", 25, 30);
		$sendmail->open();
		//echo("TO $to_mail[$i] FROM $from_mail MSG $msg BODY $body\n");
		$sendmail->send($to_mail[$i], $from_mail, trim($msg), $body);
		$sendmail->close();
	}
} catch (Exception $e) {
	//echo 'Caught exception: ',  $e->getMessage(), "\n";
	$errmsg = 'Caught exception: '.$e->getMessage()."\n";
//	fwrite($handle, $ndate."Called ADDR : ".$_SERVER["REMOTE_ADDR"].
//			",Error - ".$errmsg."\r\n");
}

if(empty($errmsg))
{
	//fwrite($handle, $ndate."Called ADDR : ".$_SERVER["REMOTE_ADDR"]."\r\n");
}
//	fclose($handle);
?>
