<?php session_start();	include_once("conn/conn.php");
require_once 'Zend/Mail.php';						//调用发送邮件的文件
require_once 'Zend/Mail/Transport/Smtp.php';		//调用SMTP验证文件
if ($_GET[name]!="" and $_GET[pass]!=""){				//激活注册用户
	//$self=$_SERVER['HTTP_REFERER'];
	$u=$_SERVER['HTTP_HOST'];
	$r=$_SERVER['PHP_SELF'];
	$l=$_SERVER['QUERY_STRING'];
	$url="http://"."$u"."$r"."?"."$l";
	$querys=mysql_query("select * from tb_voter where tb_voter_activation='$url'");
	if (mysql_num_rows($querys)>0){
		$queryes=mysql_query("update tb_voter set tb_voter_type='1' where tb_voter_activation='$url' ");
		echo "<script>alert('用户激活成功！');window.location.href='index.php';</script>";
	}else{
		echo "<script>alert('用户激活失败！');window.location.href='register.php';</script>";
	}
}

if ($_POST[submit]=="提交注册信息"){					//处理注册用户提交的数据
	//$self=$_SERVER['HTTP_REFERER'];
	$u=$_SERVER['HTTP_HOST'];
	$r=$_SERVER['PHP_SELF'];
	$l="name=".md5($_POST[tb_voter_name])."&&"."pass=".md5($_POST[tb_voter_pass]);
	$url="http://"."$u"."$r"."?"."$l";

	$tb_voter_name=trim($_POST[tb_voter_name]);
	$tb_voter_pass=md5($_POST[tb_voter_pass]);
	$tb_voter_mail=trim($_POST[tb_voter_mail]);
	$tb_voter_tel=trim($_POST[tb_voter_tel]);
	$tb_voter_address=trim($_POST[tb_voter_address]);
	$tb_voter_activation=$url;
	$tb_voter_ip=getenv("REMOTE_ADDR");
	$tb_voter_type="0";
	$query=mysql_query("insert into tb_voter(tb_voter_name,tb_voter_pass,tb_voter_mail,tb_voter_tel,tb_voter_address,tb_voter_activation,tb_voter_ip,tb_voter_type) values('$tb_voter_name','$tb_voter_pass','$tb_voter_mail','$tb_voter_tel','$tb_voter_address','$tb_voter_activation','$tb_voter_ip','$tb_voter_type')",$conn);
	if($query==true){ 
		session_register("tb_voter_name");
		session_register("tb_voter_mail");
		session_register("tb_voter_activation");	



		//发送激活邮件
	$subject="激活码的获取";
	$mailbody="欢迎您参与投票，您的激活码是："."<a href='$url'>$url</a>"."<br>"."请在IE中输入上述地址，激活您的用户！";
//定义邮件内容
	$envelope="mrsoft8888@sohu.com";		//定义登录使用的邮箱
	
	//   smtp测试版发送邮件方式，使用smtp作为服务器
				$tr = new Zend_Mail_Transport_Smtp('192.168.1.247');
				$mail = new Zend_Mail();				
				$mail->addTo($tb_voter_mail,'获取用户注册激活码');
				$mail->setFrom('cym3100@163.com','明日科技典型模块程序测试邮箱，恭喜您用户注册成功！');
				$mail->setSubject('获取注册用户的激活码');
				$mail->setBodyHtml($mailbody);
				if($mail->send($tr)==true){
					echo "<script>alert('注册成功，请到您的邮箱中获取激活码！');window.location.href='index.php';</script>";
				}else{
  					echo "<script language='javascript'>alert('您输入的邮箱地址不正确!');history.back();</script>"; 
				}
/*   网络版发送邮件方法  

	$config = array('auth' => 'login',
            'username' => 'mrsoft8888',
            'password' => 'mrsoft8888');				//定义SMTP的验证参数
	$transport = new Zend_Mail_Transport_Smtp('smtp.sohu.com', $config);		//实例化验证的对象
	$mail = new Zend_Mail('GBK');			//实例化发送邮件对象
    $mail->setBodyHtml($mailbody);				//发送邮件主体
    $mail->setFrom($envelope, '明日科技典型模块程序测试邮箱，恭喜您用户注册成功！');	//定义邮件发送使用的邮箱
    $mail->addTo($tb_voter_mail, '获取用户注册激活码');		//定义邮件的接收邮箱
    $mail->setSubject($subject);				//定义邮件主题
    //$mail->send($transport);								//执行发送操作
	if($mail->send($transport)==true){
		echo "<script>alert('注册成功，请到您的邮箱中获取激活码！');window.location.href='index.php';</script>";
}else{
  		echo "<script language='javascript'>alert('您输入的邮箱地址不正确!');history.back();</script>"; 
}
*/	
/*   网络版发送邮件方法  */	
	
	}else{
  		echo "<script language='javascript'>alert('对不起,注册失败!');history.back();</script>"; 
  	exit;
	}
}
?>