<?php
	header("Content-Type:text/html; charset=utf-8");
	require_once "../../bin/system/conver.php";
	require_once "../../dal/registryDAL.php";
	require_once dirname(__FILE__)."/../../bin/PHPMailer/class.phpmailer.php";

	$ma = conver::toDbString(trim($_POST["ma"]));
	$pa = conver::toDbString(trim($_POST["pa"]));
	$ho = conver::toDbString(trim($_POST["ho"]));
	$po = conver::toDbString(trim($_POST["po"]));
	$se = conver::toDbString(trim($_POST["se"]));
	$sm = conver::toDbString(trim($_POST["sm"]));

	$mail = new PHPMailer();
	//設定使用SMTP發送
	$mail->IsSMTP();
	//SSL
	if($se != ""){
		$mail->SMTPSecure = $se;
	}
	//指定SMTP的服務器位址
	$mail->Host = $ho;
	//$mail->Host = "smtp.gmail.com";
	//設定SMTP服務的POST
	$mail->Port = $po; //default is 25, gmail is 465 or 587
	//$mail->Port = 465; //default is 25, gmail is 465 or 587
	//設定為安全驗證方式
	$mail->SMTPAuth = $sm;
	//SMTP的帳號
	$mail->Username = $ma;
	//SMTP的密碼
	$mail->Password = $pa;
	//寄件人Email	//寄件人名稱
	$mail->SetFrom($ma,"=?UTF-8?B?".base64_encode("系統測試")."?=");
	//收件人Email
	$mail->AddAddress($ma);
	
	//回信Email及名稱
	$mail->AddReplyTo($ma,"=?UTF-8?B?".base64_encode("系統測試")."?=");
	//設定信件字元編碼
	$mail->CharSet="utf-8";
	//設定信件編碼，大部分郵件工具都支援此編碼方式
	$mail->Encoding = "base64";
	//
	$mail->SMTPKeepAlive = TRUE;
	$mail->SMTPDebug = 1; // 1: message, 2: full result
	//$mail->SMTPDebug = 2; // 1: message, 2: full result
	//設置郵件格式為HTML
	$mail->IsHTML(true);
	//每50自斷行
	$mail->WordWrap = 50;
	//郵件標題
	$mail->Subject = "=?UTF-8?B?".base64_encode("系統測試")."?=";
	//郵件內容
	$mail->Body = "寄信測試";
	//寄送郵件
	if(!$mail->Send()){
		$status = "Mailer Error: " . $mail->ErrorInfo;
	}else{
		$status = "Mailer Success";
	}
	echo $status;
?>