<?php 
require '../function/conn.php';
require '../function/function.php';
$action=urlencode($_REQUEST["action"]);
$mailto=urlencode($_REQUEST["to"]);
if(strpos(URLDecode($mailto),"@")===false) {
	die("error|邮箱格式不正确！");
}
if($action=="pwd") {
	$_SESSION["pwd_code"]=rand(10000, 99999);
	mysqli_query($conn,"update ".TABLE."member set M_pwdcode='".$_SESSION["pwd_code"]."' where M_email like '".URLDecode($mailto)."'");
	$send=sendmail("您的验证码[".$_SESSION["pwd_code"]."]","您的验证码为 <b>".$_SESSION["pwd_code"]."</b>，请妥善保管不要告诉他人。",URLDecode($mailto)) ;
		if($send=="success") {
			die("success|发送成功！");
		} else {
			die("error|".$send);
		}
}
if($action=="edit") {
	$_SESSION["edit_code"]=rand(10000, 99999);
	$sql="Select * from ".TABLE."member Where M_email like '".URLDecode($mailto)."' and not M_id=".$_SESSION["M_id"];
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if (mysqli_num_rows($result) > 0) {
		die("error|邮箱已被占用，请换其他邮箱!");
	} else {
		mysqli_query($conn,"update ".TABLE."member set M_pwdcode='".$_SESSION["edit_code"]."',M_email='".URLDecode($mailto)."' where M_id=".$_SESSION["M_id"]);
		$send=sendmail("您的验证码[".$_SESSION["edit_code"]."]","您的验证码为 <b>".$_SESSION["edit_code"]."</b>，请妥善保管不要告诉他人。",URLDecode($mailto)) ;
		if($send=="success") {
			die("success|发送成功！");
		} else {
			die("error|".$send);
		}
	}
}
if($action=="login") {
	$_SESSION["login_code"]=rand(10000, 99999);
	$sql="Select * from ".TABLE."member Where M_email like '".URLDecode($mailto)."'";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if (mysqli_num_rows($result) > 0) {
		mysqli_query($conn,"update ".TABLE."member set M_pwdcode='".$_SESSION["login_code"]."' where M_email like '".URLDecode($mailto)."'");
		$send=sendmail("您的验证码[".$_SESSION["login_code"]."]","您的验证码为 <b>".$_SESSION["login_code"]."</b>，请妥善保管不要告诉他人。",URLDecode($mailto)) ;
		if($send=="success") {
			die("success|发送成功！");
		} else {
			die("error|".$send);
		}
	} else {
		die("error|此邮箱尚未注册会员，请先注册！");
	}
}
if($action=="reg") {
	$_SESSION["reg_code"]=rand(10000, 99999);
	$sql="Select * from ".TABLE."member Where M_email like '".URLDecode($mailto)."'";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if (mysqli_num_rows($result) > 0) {
		die("error|邮箱已被注册使用，请直接登录");
	} else {
		$send=sendmail("您的验证码[".$_SESSION["reg_code"]."]","您的验证码为 <b>".$_SESSION["reg_code"]."</b>，请妥善保管不要告诉他人。",URLDecode($mailto)) ;
		if($send=="success") {
			die("success|发送成功！");
		} else {
			die("error|".$send);
		}
	}
}
?>