<?php

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

/*
	普通邮件发送函数
	$subject	主题
	$address	收件人地址
	$list		抄送人地址
	$content	邮件主体
*/
function mail_send( $subject,$address,$list,$content ){	
	global $Project;
	global $Setting;
	
	//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	  = $Project["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       = $Setting["mail"]["MAIL_SMTP_HOST"]; // sets the SMTP server
	$mail->Port       = $Setting["mail"]["MAIL_SMTP_PORT"];                    // set the SMTP port for the GMAIL server
	$mail->Username   = $Setting["mail"]["MAIL_USER"]; // SMTP account username
	$mail->Password   = $Setting["mail"]["MAIL_PASS"];        // SMTP account password
	
	$mail->SetFrom($Setting["mail"]["MAIL_SMTP_FROM"], $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;
	}
	
}
?>