<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	邮件发送函数包
*
*	$Id: veryide.function.php,v2.0 14:01 2009-03-31 Lay $
*/

/*
	普通邮件发送函数
	$subject	主题
	$address	收件人地址
	$list		抄送人地址
	$content	邮件主体
*/
function mail_send( $subject,$address,$list,$content ){	
	global $_G;
	
	//class
	require_once( dirname(__FILE__)."/../config/mail.php");
	require_once( dirname(__FILE__).'/../class/class.phpmailer.php');
	
	error_reporting(E_STRICT);
	
	$mail             = new PHPMailer();
	$mail->CharSet	  = $_G['product']['charset'];
	
	//$body             = stripslashes($_POST["content"]);
	$body             = eregi_replace("[\]",'',$content);
	
	$mail->IsSMTP(); // telling the class to use SMTP
	//$mail->Host       = "smtp.qq.com"; // SMTP server
	//$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
											   // 1 = errors and messages
											   // 2 = messages only
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->Host       = $_G['setting']["mail"]["MAIL_SMTP_HOST"]; // sets the SMTP server
	$mail->Port       = $_G['setting']["mail"]["MAIL_SMTP_PORT"];                    // SET the SMTP port for the GMAIL server
	$mail->Username   = $_G['setting']["mail"]["MAIL_USER"]; // SMTP account username
	$mail->Password   = $_G['setting']["mail"]["MAIL_PASS"];        // SMTP account password
	
	$mail->SetFrom($_G['setting']["mail"]["MAIL_SMTP_FROM"], $_G['setting']["mail"]["MAIL_SMTP_NAME"]);
	
	//$mail->AddReplyTo("name@yourdomain.com","First Last");
	
	$mail->Subject    = $subject;
	
	//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
	
	$mail->MsgHTML($body);
	
	//$address = "verywork@gmail.com";
	$mail->AddAddress($address);
	
	if( $list ){
		$array = explode(",",$list);
		foreach( $array as $address ){
			$mail->AddBCC(trim($address));
		}
	}
	
	//$mail->AddAttachment("image/phpmailer.gif");      // attachment
	//$mail->AddAttachment("image/phpmailer_mini.gif"); // attachment
	
	if(!$mail->Send()) {
		return false;
	} else {
		return true;
	}
	
}
?>