<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Hc_mail_lib
{
	/*
	public  $mail_config = array();
	function __construct( $mail_config = array())
	{
		//parent::__construct();
		if(!empty($mail_config)){
			$mail->Port 		= $mail_config['mail_send_port'];
			$mail->Host 		= $mail_config['mail_localhost'];
			$mail->Username 	= $mail_config['mail_user_name'];
			$mail->Password 	= $mail_config['mail_passwd']; 
			//$mail->IsSendmail(); //如果没有sendmail组件就注释掉，否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示
			$mail->AddReplyTo($mail_config['mail_reply'], $mail_config['mail_reply_name']);//回复地址
			if($mail_config['mail_from']!=''){
				$mail->From 		= $mail_config['mail_from'];
			}else{
				$mail->From 		= $mail_config['mail_user_name'];
			}
			if($mail_config['mail_from_name']!=''){
				$mail->FromName 	= $mail_config['mail_from_name'];
			}else{
				$mail->FromName 	= $mail_config['mail_reply_name'];
			}
		}else{
			exit('need_config_mail_systeim!');
		}
	}*/

	function send_mail( $send_arr = array(), $mail_config = array() )
	{
		header("content-type:text/html;charset=utf-8");
		ini_set("magic_quotes_runtime",0);
		require_once ROOT_PATH.'application/phpmailer/class.phpmailer.php';
		try {
			$mail = new PHPMailer(true);
			$mail->IsSMTP();
			$mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码
			$mail->SMTPAuth = true; //开启认证

			if(!empty($mail_config)){
				if($mail_config['mail_send_port']!=''){
					$mail->Port 		= $mail_config['mail_send_port'];
				}
				if($mail_config['mail_localhost']!=''){
					$mail->Host 		= $mail_config['mail_localhost'];
				}
				$mail->Username 	= $mail_config['mail_user_name'];
				$mail->Password 	= $mail_config['mail_passwd']; 
				//$mail->IsSendmail(); //如果没有sendmail组件就注释掉，否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示
				if($mail_config['mail_reply']==''){
					$mail_config['mail_reply'] =  $mail_config['mail_user_name'];
				}
				if($mail_config['mail_reply_name']==''){
					$mail_config['mail_reply_name'] =  $mail_config['mail_user_name'];
				}
				
				$mail->AddReplyTo($mail_config['mail_reply'], $mail_config['mail_reply_name']);//回复地址
				
				if($mail_config['mail_from']!=''){
					$mail->From 		= $mail_config['mail_from'];
				}else{
					$mail->From 		= $mail_config['mail_user_name'];
				}
				if($mail_config['mail_from_name']!=''){
					$mail->FromName 	= $mail_config['mail_from_name'];
				}else{
					$mail->FromName 	= $mail_config['mail_reply_name'];
				}
			}else{
				exit('need_config_mail_systeim!');
			}
		

			$mail->AddAddress($send_arr['to']);
			$mail->Subject =$send_arr['subject'];
			$mail->Body = $send_arr['body']; 
			if($send_arr['alt_body']!=''){
				$mail->AltBody = $send_arr['alt_body']; 
			}
			$mail->WordWrap = 80; // 设置每行字符串的长度
			//$mail->AddAttachment("f:/test.png"); //可以添加附件
			$mail->IsHTML(true);
		
			$mail->Send();
			return true;
		} catch (phpmailerException $e)
		{
			return false;
		}
	}
	
}