1

我有一个用户激活脚本,它发送一封电子邮件来激活他的帐户。我的问题是服务器发送相同的电子邮件 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.";
                }
        }
    }
 }
 ?>

这是一张图片:

4

3 回答 3

2

删除标记行:$message = "您已成功注册 Block Builder Fighter!\n要激活您的帐户,请单击下面的链接或将其粘贴到您浏览器的 URL 栏中:\n\n\nhttp://bbf-gima. hostoi.com/user/active.php?code=$code\n\n"; /* 删除或标记为评论邮件($email, $subject, $message, "From: no-reply_BBF"); */ if(!mail($email, $subject, $message, "From: no-reply_BBF"))

然后再试一次

于 2013-09-06T19:39:09.400 回答
1

更改以下行:

        mail($email, $subject, $message, "From: no-reply_BBF");
        if(!mail($email, $subject, $message, "From: no-reply_BBF"))

至:

            $isSent = mail($email, $subject, $message, "From: no-reply_BBF");
            if(!isSent)

应该解决问题。

另外作为旁注,您应该使用mysqli而不是mysql

于 2013-09-06T19:43:57.917 回答
1

你打电话mail()两次:

mail($email, $subject, $message, "From: no-reply_BBF");
if(!mail($email, $subject, $message, "From: no-reply_BBF"))

它应该是

$sent = mail($email, $subject, $message, "From: no-reply_BBF");
if(!$sent)
于 2013-09-06T19:40:49.203 回答