<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &讨论组基类文件&
 */

if (!defined('IS_RUN')) die('Forbidden');

class tj_mail extends tj_model {

	var $table = 'dbpre_mail';

	function __construct() {
		parent::__construct();
		$this->init_field();
	}

    function msm_mailouncement() {
        $this->__construct();
    }

	function init_field() {
		$this->add_field('');
		$this->add_field_fun('', 'intval');
        $this->add_field_fun('', '_T');
	}

	//发送邮件
	function postMail($sendmail,$subject,$content){
	
		global $_G;
	
		$options = fileRead(TUNTRON_DAT.'/mail_options.php');
		date_default_timezone_set('Asia/Shanghai');
		require_once TUNTRON_INC.'/PHPMailer/class.phpmailer.php';
		$mail = new PHPMailer();

		//邮件配置
		$mail->CharSet = "UTF-8";
		$mail->IsSMTP(); 
		$mail->SMTPDebug  	= 1;
		$mail->SMTPAuth   	= true;           
		$mail->Host       		= $options['mailhost']; 
		$mail->Port       		= $options['mailport']; 
		$mail->Username   	= $options['mailuser']; 
		$mail->Password   	= $options['mailpwd'];
		//POST过来的信息
		$frommail		= $options['mailuser'];
		$fromname	= $_G['siteinfo']['SiteName'];
		$replymail		= $options['mailuser'];
		$replyname	= $_G['siteinfo']['SiteName'];
		$sendname	= '';
		$this->check_post($frommail,$subject,$content,$sendmail);
		if(empty($frommail) || empty($subject) || empty($content) || empty($sendmail)){
			return '0';
		}else{

			//邮件发送
			$mail->SetFrom($frommail, $fromname);
			$mail->AddReplyTo($replymail,$replyname);
			$mail->Subject    = $subject;
			$mail->AltBody    = "要查看邮件，请使用HTML兼容的电子邮件阅读器!"; 
			//$mail->MsgHTML(eregi_replace("[\]",'',$content));
			$mail->MsgHTML(strtr($content,'[\]',''));
			$mail->AddAddress($sendmail, $sendname);
			$mail->Send();
			
			return '1';
			
		}
	}
    function check_post($frommail,$subject,$content,$sendmail) {
        if(!$frommail) Note('发送邮件未配置！');
        if(!$subject) Note('邮件主题不能为空！');
		if(!$content) Note('邮件内容不能为空！');
		if(!$sendmail) Note('发送目标Email地址不能为空！');
    }
}
?>