<?php

error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

// 載入 init.php
require_once ("./etc/init.php");
include_once ("./etc/phpMailer/class.phpmailer.php");

$mail             = new PHPMailer();

// 由 operator 判斷需要寄出什麼信件
switch ($my_user->operator)
{
	// 寄送認證信
	case "identification":                    
		// 讀出認證信範本
		// $body = $mail->getFile('content_identification.html');
		// 讀出認證信內容
		$body = $body . $my_user->get_activate_mailbody();
		$body = eregi_replace("[\]",'',$body);
		break;
	// 寄送密碼信
	case "new_password":
        // 讀出密碼信內容
        $body = $body . $my_user->get_new_password_mailbody();
        $body = eregi_replace("[\]",'',$body);
		break;
	// 寄送 hadoop 帳號密碼信
	case "hadoop_user_password":
        // 讀出 hadoop 帳號密碼信內容
        $body = $body . $my_user->get_hadoop_user_password_mailbody();
        $body = eregi_replace("[\]",'',$body);
        break;	
}


$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = $mail_server_host;     // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server

$mail->Username   = $mail_user;            // GMAIL username
$mail->Password   = $mail_password;  	   // GMAIL password

$mail->AddReplyTo($mail_account , $mail_account_name);

$mail->From       = $mail_account;
$mail->FromName   = $mail_account_name;

$mail->Subject    = "Hadoop 帳號系統信";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 50; // set word wrap

$mail->CharSet="utf-8";                                   // 設定e-mail編碼
 
$mail->Encoding = "base64";                               // 設定信件編碼

$mail->MsgHTML($body);

$mail->AddAddress($my_user->email, "");  	              // 寄件地址，顯示名稱

$mail->AddAttachment("images/phpmailer.gif");             // attachment

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
	$message = "Mailer Error: " . $mail->ErrorInfo;
	echo "<BR>" . $message;
  	// $my_user->redirect_to("http://$w_localhost", $message); 
} else {
    // $message = "Message sent!"; 
    // $my_user->redirect_to("http://$w_localhost", $error_message);
}

?>
