<?php
	use PHPMailer\PHPMailer\PHPMailer;
	use PHPMailer\PHPMailer\Exception;

	header("Content-Type:text/html; charset=utf-8");
	require_once "pageBase.php";
	require_once "../../bin/system/conver.php";
	require_once "../../dal/registryDAL.php";
	require_once dirname(dirname(dirname(__FILE__)))."/bin/PHPMailer/src/Exception.php";
	require_once dirname(dirname(dirname(__FILE__)))."/bin/PHPMailer/src/PHPMailer.php";
	require_once dirname(dirname(dirname(__FILE__)))."/bin/PHPMailer/src/SMTP.php";

	class smtp extends pageBase {
		public function load() {
			$ma = parent::getPost("ma");
			$pa = parent::getPost("pa");
			$ho = parent::getPost("ho");
			$po = parent::getPost("po");
			$se = parent::getPost("se");
			$sm = parent::getPost("sm");
			$from_txt = "=?UTF-8?B?".base64_encode("系統測試")."?=";
			$body_txt = "寄信測試";

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