<?php
require ROOT_PATH.'/application/phpmailer/class.phpmailer.php';
$PHPmail = new PHPMailer(true);

class Gvmail
{
	var $PHPmailval = array();
	function Gvmail()
	{
		//查询stmp服务设置
		$mailsql = " SELECT cfs_codestr,cfs_value FROM ".$this -> db -> prefix."configsys  WHERE cfs_type ='mail' LIMIT 0, 10 ";
		
		$info = $this -> db -> select_info($mailsql);

		foreach($info as $key => $val)
		{
			$this -> PHPmailval[$val["cfs_codestr"]] = $val["cfs_value"];
		}
		

		
	}
	
	function tosendmail( $toval = '', $subjectval = '', $bodyval = "", $type="reg" , $replytoval = ""  , $replytoName = "")
	{
			
			$GLOBALS['PHPmail'] -> IsSMTP();                     
			$GLOBALS['PHPmail'] -> SMTPAuth   = true;          
			$GLOBALS['PHPmail'] -> Port       = 25;    
			
			if($this -> PHPmailval["mailhost"]!='')
			{
				$GLOBALS['PHPmail'] -> Host       =  $this -> PHPmailval["mailhost"]; 		  
				$GLOBALS['PHPmail'] -> Username   =  $this -> PHPmailval["username"];      
				$GLOBALS['PHPmail'] -> Password   =  $this -> PHPmailval["password"];
			}
			
			if( $this -> PHPmailval["replyto"]!='')
			{
				$GLOBALS['PHPmail'] ->AddReplyTo($this -> PHPmailval["replyto"], $this -> PHPmailval["replytoname"]);  
			}
			
			if( $this -> PHPmailval["from"]!='')
			{
				$GLOBALS['PHPmail'] -> From       =  $this -> PHPmailval["from"];
				$GLOBALS['PHPmail'] -> FromName   =  $this -> PHPmailval["fromname"];
			}
			
			
			if($replytoval != '' and $replytoName !='' )
			{
				$GLOBALS['PHPmail'] ->AddReplyTo($replytoval,$replytoName);  ////回复地址
			}
			

			if($toval !=='' and $subjectval !='' and $bodyval !='')
			{
				$GLOBALS['PHPmail'] ->AddAddress($toval);
			
				$GLOBALS['PHPmail'] ->Subject  = $subjectval;
			
				//$GLOBALS['PHPmail'] ->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test //当邮件不支持html时备用显示，可以省略
				
				$GLOBALS['PHPmail'] ->WordWrap   = 80; //set word wrap // 设置每行字符串的长度
				
				//$GLOBALS['PHPmail'] ->AddAttachment("f:/test.png"); //可以添加附件
			
				$GLOBALS['PHPmail'] ->MsgHTML($bodyval);
			
				$GLOBALS['PHPmail'] ->IsHTML(true); // send as HTML
				
				return $GLOBALS['PHPmail'] ->Send();
			}else{
				return false;
			}
			
	
	}
	
	function getbody( $tmpval = 'reg' )
	{
		$body             = file_get_contents(ROOT_PATH.'/templates/tmp/'.$tmpval.'_tpl.html');
		return $body      = preg_replace('/\\\\/','', $body);  
	}
	
}

$Gvmail = new Gvmail();

?>
