[英]mail() functions sends 2 same email
I have a user activation script which sends a email to activate his account. 我有一个用户激活脚本,它发送一封电子邮件来激活他的帐户。 My problem is that the server sends the same email 2 times.
我的问题是服务器发送相同的电子邮件2次。 Is there any way to fix this?
有没有什么办法解决这一问题? Here is my script
这是我的剧本
<?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.";
}
}
}
}
?>
Here is a picture: 这是一张图片:
Remove marked line: $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"; 删除标记行:$ message =“您已成功注册到Block Builder Fighter!\\ n要激活您的帐户,请单击下面的链接或将其粘贴到您的broswer的URL栏中:\\ n \\ n \\ nhttp:// bbf-gima。 hostoi.com/user/active.php?code=$code\\n\\n“; /* remove or mark as comment mail($email, $subject, $message, "From: no-reply_BBF");
/ *删除或标记为评论邮件($ email,$ subject,$ message,“From:no-reply_BBF”); */ if(!mail($email, $subject, $message, "From: no-reply_BBF"))
* / if(!mail($ email,$ subject,$ message,“From:no-reply_BBF”))
and try again 然后再试一次
You are calling mail()
twice : 您正在调用
mail()
两次:
mail($email, $subject, $message, "From: no-reply_BBF");
if(!mail($email, $subject, $message, "From: no-reply_BBF"))
It should be 它应该是
$sent = mail($email, $subject, $message, "From: no-reply_BBF");
if(!$sent)
Change the following lines: 更改以下行:
mail($email, $subject, $message, "From: no-reply_BBF");
if(!mail($email, $subject, $message, "From: no-reply_BBF"))
To: 至:
$isSent = mail($email, $subject, $message, "From: no-reply_BBF");
if(!isSent)
Should fix the issue. 应该解决这个问题。
Also as a side note, you should use mysqli
instead of mysql
另外作为旁注,你应该使用
mysqli
而不是mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.