<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body   >
<?php
require('mail/class.phpmailer.php');//邮件发送类
	
$ls_msg = mailer($_POST);
	
/**
 * 发送邮件
 * @param  string $to        接收人邮件地址
 * @param  string $title     邮件标题
 * @param  string $contents  邮件内容
 * @param  string $type      判断是否要加附件
 * @param  string $accessory 附件的名字
 * @return                   成功返回true,失败返回错误信息
 */
function sendEmail($to,$title,$contents,$type = '',$accessory =''){
    $mail = new PhpMailer(true);
    $mail->IsSMTP();
    $mail->CharSet ="UTF-8";//编码
    $mail->Debugoutput = 'html';
    $mail->Host = "smtp.ym.163.com";//HOST 地址
    $mail->Port = 25;//端口
    $mail->SMTPAuth = true;
    $mail->Username = "shiys@lanscend.com";//用户名
    $mail->Password = "ls87085738";//密码
    $mail->SetFrom("shiys@lanscend.com","Web Feedback");//发件人地址, 发件人名称
    $mail->AddAddress($to);//收信人地址

    if (!empty($type)) {
     $mail->AddAttachment($type,$accessory); // 添加附件,并指定名称 
    }
    $mail->Subject = $title;//邮件标题
    $mail->MsgHTML($contents);
    if ($mail->Send()){
       return true;
    }else{
       echo $mail->errorMessage();
    }
}

function mailer($postvars,$lang="en"){

	require_once('conn.php');
	$opendb=new mydb();
	require_once('char_set.php');
	
	//$Subject="Information from ".$_SERVER['HTTP_HOST'];  /* 标题*/

	$config_sql="select * from ls_config ";
	$config_query=$opendb->query($config_sql);
	$config_rows=mysql_fetch_assoc($config_query);
	$emailAddress=$config_rows['feedbackEmail'];

	if(count($postvars)!=0)  //pass vars fron URL
	{
		while(list($akey,$avalue)=each($postvars))
		{
			if(strpos($akey,"mail")!==false)  //获得客户邮件地址
			{$email_from=trim($avalue);}
			switch ($akey){
			case "Mr":
			$Mr=$avalue;
			break;
			case "name":
			$name=$avalue;
			break;
			case "ls2":
        	break;
			case "business":
        	break;
			case "code":
        	break;
			case "submit":
        	break;
			
			default:
			if(strpos($akey,"select")===0||strpos($akey,"button")===0){break;}
			$Content.=urldecode($akey).":  ";
			$Content.=urldecode($avalue)."<br/>\r\n";
			break;
			}
		}
	}
	$Content .="<br/>\r\n".date('Y-m-d');
	
	if(sendEmail($emailAddress, "Web Feedback From ".$_SERVER['HTTP_HOST'], $Content)){
		
		foreach($postvars  as $akey => $avalue){
			switch (urldecode($akey)){
			case "Subject":
       		$subject=$avalue;
       		break;
    		case "Comments":
       		$comments=$avalue;
       		break;
    		case "Name":
        	$username=$avalue;
       		break;
    		case "Companyname":
			$companyname=$avalue;
        	break;
			case "Address":
			$address=$avalue;
        	break;
    		case "Tel":
			$tel=$avalue;
        	break;
			case "Fax":
			$fax=$avalue;
        	break;
    		case "Mail":
			$mail=$avalue;
        	break;
			case "Web":
			$http=$avalue;
        	break;
    		case "path":
			$path=$avalue;
        	break;
    		case "pro_id":
			$pro_id=$avalue;
        	break;
			case "guid":
			$guid=$avalue;
        	break;
			case "business":
			$business=$avalue;
        	break;
    		}
		}
		
		require_once('ls_admin/inc/char_set.php');
		require_once('ls_admin/inc/ls_syscode.php');
		
		date_default_timezone_set('Asia/Shanghai');//设置时区为中国时间
		if($path == NULL)
			$path = $subject;
		
		$gifo = new get_gust_info();
		$ip_home = '';
		$ipadds = $gifo->Getaddress();
		foreach($ipadds[0] as $value){
			 $ip_home .= " ".iconv("utf-8","utf-8",$value);    
		}
		if($ip_home == NULL)
			 $ip_home = "本地";
		
		if($pro_id != null){
			$insert_pro_feedback_sql=sprintf("insert into ls_pro_feedback(requirement,name,company,tel,email,path,date,ip,explorer,home,system,proID,cateNameID) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						GetSQLValueString($comments,"text"),
						GetSQLValueString($username,"text"),
						GetSQLValueString($companyname,"text"),
						GetSQLValueString($tel,"text"),
						GetSQLValueString($mail,"text"),
						GetSQLValueString($path,"text"),
						GetSQLValueString(date("Y-m-d H:i:s"),"text"),
						GetSQLValueString($gifo->Getip(),"text"),
						GetSQLValueString($gifo->GetBrowser()." - ".$gifo->GetLang(),"text"),
						GetSQLValueString($ip_home,"text"),
						GetSQLValueString($gifo->GetOs(),"text"),
						GetSQLValueString($pro_id,"int"),
						GetSQLValueString($business,"int")
						);
			$insert_query=$opendb->query($insert_pro_feedback_sql);

		}else{
			$insert_pro_feedback_sql=sprintf("insert into ls_pro_feedback(requirement,name,company,tel,http,fax,email,path,address,date,ip,explorer,home,system,proID,cateNameID) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						GetSQLValueString($comments,"text"),
						GetSQLValueString($username,"text"),
						GetSQLValueString($companyname,"text"),
						GetSQLValueString($tel,"text"),
						GetSQLValueString($http,"text"),
						GetSQLValueString($fax,"text"),
						GetSQLValueString($mail,"text"),
						GetSQLValueString($path,"text"),
						GetSQLValueString($address,"text"),
						GetSQLValueString(date("Y-m-d H:i:s"),"text"),
						GetSQLValueString($gifo->Getip(),"text"),
						GetSQLValueString($gifo->GetBrowser()." - ".$gifo->GetLang(),"text"),
						GetSQLValueString($ip_home,"text"),
						GetSQLValueString($gifo->GetOs(),"text"),
						GetSQLValueString($pro_id,"int"),
						GetSQLValueString($business,"int")
						);
			$insert_query=$opendb->query($insert_pro_feedback_sql);
		}
		
		if($lang=="cn"){
			return($sendmailOKMsgcn==""?"谢谢，我们尽快和您取得联系":$sendmailOKMsgcn);//成功 
		}else{
			return($sendmailOKMsg==""?"THANK YOU FOR CONTACTING US, OUR CUSTOMER SERVICE REPRESENTATIVE WILL CONTACT YOU WITHIN 24 HOURS. THANK YOU AGAIN":$sendmailOKMsg);//成功 
		}
	}else{
		if($lang=="cn"){
			return($sendmailFailMsgcn==""?"抱歉，您的反馈信息未能发出":$sendmailFailMsgcn);// 失败给提示
		}else{
			return($sendmailFailMsg==""?"SORRY, YOUR MESSAGE SENDING FAILURE":$sendmailFailMsg);
		}
	}
	
	
}

?>
</body>
</html>