我有一个用户激活脚本,它发送一封电子邮件来激活他的帐户。我的问题是服务器发送相同的电子邮件 2 次。有没有什么办法解决这一问题?这是我的脚本
<?php
include ('global.php');
if($_POST['submit']){
$username = addslashes(strip_tags($_POST['username']));
$password = addslashes(strip_tags($_POST['password']));
$email = addslashes(strip_tags($_POST['email']));
$enpass = $_POST['password'];
$ip = $_SERVER['REMOTE_ADDR'];
if(empty($username) || empty($password) || empty($_POST['email']) || $_POST['test'] == 'pcs' || strlen($username) < 6 || strlen($username) > 25 || strlen($password) < 6 ){
echo "<center>";
if(empty($username)){
echo "<font color='color' size='25'>*</font>Username is required."."<br>";
}
if(empty($password)){
echo "<font color='color' size='25'>*</font>Password is required."."<br>";
}
if(empty($_POST['email'])){
echo "<font color='color' size='25'>*</font>Email is required."."<br>";
}
if($_POST['test'] == 'pcs'){
echo "<font color='color' size='25'>*</font>Please choose something."."<br>";
}
if(strlen($username) < 6 || strlen($username) > 25){
echo "<font color='color' size='25'>*</font>Username must be between 6 and 25 characters!"."<br>";
}
if(strlen($password) < 6){
echo "<font color='color' size='25'>*</font>Password must be atleast 6 characters!"."<br>";
}
}else{
$password = md5($password);
$check = mysql_query("SELECT * FROM users WHERE username='$username'");
if(mysql_num_rows($check)>=1)
echo "User already taken";
else{
$code = rand(11111111, 99999999);
//apostoli email
$email = $_REQUEST['email'] ;
$subject = "Email activation";
$headers = "From: noreply_bbf-activation";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "You have successully registered to Block Builder Fighter! \nTo activate your account click the link below or paste it into the URL bar of your broswer:\n\n\nhttp://bbf-gima.hostoi.com/user/active.php?code=$code\n\n<?php echo 'works'; ?>";
mail($email, $subject, $message, "From: no-reply_BBF");
if(!mail($email, $subject, $message, "From: no-reply_BBF"))
echo "We couldn't sign you up at this time. Please try again later.";
else{
//register ton xristi
$query = mysql_query("INSERT INTO users (`id`, `username`, `password`, `email`, `registered_ip`, `code`, `active`) VALUES ('', '".$username."', '".$password."', '".$email."', '".$ip."', '".$code."', '0')");
echo "You have been registered successfully! Please check your email($email) to activate your account. If you don't see any email check your spam folder.";
}
}
}
}
?>
这是一张图片: