php邮件两次发送邮件

时间:2014-10-06 11:22:02

标签: php email phpmailer

我有一个PHP脚本,应该在注册完成时发送电子邮件。只要有人注册了电子邮件并且我收到了,就可以正常工作。但是,我注意到有时我会在一小时后收到相同的电子邮件。有时它甚至会突然向我发送一封电子邮件,用于几周前收到的注册。

$key=$_GET[key];
    if(isset($key) || !empty($key)){
        $query1=mysql_query("SELECT * FROM registration WHERE value='$key'");
        while($question_list = mysql_fetch_array($query1)){
            $num_questions=mysql_num_rows($query1);
            $title= $question_list['title'];
            $firstname=$question_list['firstname'];
            $lastname=$question_list['familyname'];
            $dateofbirth=$question_list['dob'];
            $gender=$question_list['gender'];
            $nationality=$question_list['nationality'];
            $email=$question_list['email'];
            $to = "userregistration@yahoo.com";
            $subject = "Registration";
            $message = "Hello! Registration, see below."."\n";
            $message.="\n";
            $message.="Title: ";
            $message.=$title."\n";
            $message.="First Name: ";
            $message.=$firstname."\n";
            $message.="Last Name: ";
            $message.=$lastname."\n";
            $message.="Gender: ";
            $message.=$gender."\n";
            $message.="Date of Birth: ";
            $message.=$dateofbirth."\n";
            $message.="Nationality: ";
            $message.=$nationality."\n";
            $message.="Email Address: ";
            $message.=$email."\n";
            $message.="Telephone: ";
            $message.=$telephone."\n";
            $from = "registration@yahoo.com";
            $headers = "From:" . $from;
            mail($to,$subject,$message,$headers);
        }
    }

1 个答案:

答案 0 :(得分:2)

将您的SQL查询更改为

"SELECT * FROM registration WHERE value='$key' LIMIT 0,1"

这样它只会发送一次邮件

如果您从表中获得2条记录,则在您的问题列表中

然后您将最终发送一次邮件两次。