邮件表单向服务器发送双份副本

时间:2015-06-27 21:06:40

标签: php email

我在php中制作了一个邮件表格,突然间(深夜编程:)它开始向服务器端发送双重消息。验证输入字段,域和mx记录后,它会在下面的函数中准备邮件。我正在使用" getMX-function"在其他地方毫无问题地保持不变,所以我得出结论,错误必定在某处,但我现在却盯着它看......我被卡住了!

当访问者邮件成功发送到服务器(email@website.com)时,服务器将向访问者发送响应电子邮件,告诉他服务器收到了他的消息。有一次访客和服务器都得到了双份副本,但不知怎的,我似乎已经修好了访客的一部分......不要问我怎么样,早上是5.30,模糊不清的东西。服务器继续获得双份副本,正如我所说,我现在盯着它看。

我希望其他人可以在下面的代码中指出一个明显的错误,或者可能得出我应该在其他地方寻求的结论。我已经从它的先前版本中更改了此代码,以使其与引导程序网页一起使用,以及问题开始时的情况。

谢谢!

<?

if(isset($_POST['send'])){
    $verification=$_POST['keystring'];
    if($verification==$_SESSION['keystring']){
        sendMail($_POST['cname'],$_POST['cmail'],$ctext,$contact);
        unset($_POST['send']);
    }else{
        print("<div class=\"col-sm-12 error\">Error message</div>");
    }
}

@set_time_limit(0);

function sendMail($client_name,$client_email,$client_message,$contact){
    if(checkFields($client_name,$client_email,$client_message)!=true){
        print($error);
    }else{
        $client_message=rtrim($client_message,"\n");
        if(isset($contact)){
            $server_email=$contact;
            $server_sender=$contact;
        }else{
            $server_email="email@website.com";
            $server_sender="email@website.com";
        }
        $server_name="website.com";
        $server_subject="Mailform response message";
        $server_headers="MIME-Version: 1.0\r\n".
            "Content-type: text/html; charset=utf-8\r\n".
            "From: \"$client_name\" <".$client_email.">\r\n".
            "To: \"$server_name\" <".$server_email.">\r\n".
            "Date: ".date("r")."\r\n".
            "Subject: ".$server_subject."\r\n";
        $server_message="<html>\r\n".
            "<body>\r\n".
            "<h4>$client_name - $client_email</h4>\r\n".
            "<h4>$client_message</h4>\r\n".
            "<h4> Origin: ".$_SERVER['REMOTE_ADDR']." </h4>\r\n".
            "</body>\r\n".
            "</html>\r\n";
        $server_response=getMX($server_email,$server_subject,$server_message,$client_email,$server_headers);
        if($server_response[0]){
            print("<div class=\"col-sm-12\"><h4 class=\"success\">Success message server</h4>".$server_response[1]."</div>\n");
            $client_headers="MIME-Version: 1.0\r\n".
                "Content-type: text/html; charset=utf-8\r\n".
                "From: \"$server_name\" <".$server_sender.">\r\n".
                "To: \"$client_name\" <".$client_email.">\r\n".
                "Date: ".date("r")."\r\n".
                "Subject: ".$server_subject."\r\n";
            $server_message="<html>\r\n".
                "<body>\r\n".
                "<h4>Thank you for visiting our website!</h4>\r\n".
                "<h4>We will get back to you as soon as possible</h4>\r\n".
                "</body>\r\n".
                "</html>\r\n";
            $client_response=getMX($client_email,$server_subject,$server_message,$server_sender,$client_headers);
            if($client_response[0]){
                print("<div class=\"col-sm-12\"><h4 class=\"confirm\">Confirmation response was sent</h4>".$client_response[1]."</div>\n");
            }else{
                print("<div class=\"col-sm-12\"><h4 class=\"error\">Confirmation response was not sent</h4>".$client_response[1]."</div>\n");
            }
            unset($_POST['cname']);
            unset($_POST['cmail']);
            unset($_POST['ctext']);
        }else{
            print("<div class=\"col-sm-12\"><h4 class=\"success\">Success message client</h4><br />".$server_response[1]."</div>\n");
            unset($_POST['cname']);
            unset($_POST['cmail']);
            unset($_POST['ctext']);
        }
    }
}

?>

html表单生成如下:

<?

$imgverify="?".session_name()."=".session_id();
$html="<div class=\"col-sm-12\">\n";
    $html.="<h3>Kontakt</h3>\n";
    $html.="Send us a mail :)<br /><br />";
    $html.="<div class=\"mailform\" id=\"mailform\">\n"; // added "id=mailform" for centerScroll javascript function.
        $html.="<form role=\"form\" action=\"#mailform\" method=\"post\">\n"; // added "action=#mailform" for centerScroll javascript function.
            $html.="<div class=\"form-group\">\n";
                $html.="<label for=\"cname\">Name</label>\n";
                $html.="<input type=\"text\" class=\"form-control\" id=\"cname\" name=\"cname\" placeholder=\"Enter name\" value=\"".$_POST['cname']."\">\n";
            $html.="</div>\n";
            $html.="<div class=\"form-group\">\n";
                $html.="<label for=\"cmail\">Email</label>\n";
                $html.="<input type=\"email\" class=\"form-control\" id=\"cmail\" name=\"cmail\" placeholder=\"Enter email address\" value=\"".$_POST['cmail']."\">\n";
            $html.="</div>\n";
            $html.="<div class=\"form-group\">\n";
                $html.="<label for=\"ctext\">Message</label>\n";
                $html.="<textarea class=\"form-control\" rows=\"5\" id=\"ctext\" name=\"ctext\" placeholder=\"Enter message\">".$_POST['ctext']."</textarea>\n";
            $html.="</div>\n";
            $html.="<div class=\"form-group\">\n";
                $html.="<label for=\"imgver\">Fill in the code before sending</label>\n";
                $html.="<table>\n<tr>\n";
                    $html.="<td style=\"width:100%;\">\n";
                        $html.="<div><input type=\"text\" class=\"form-control\" id=\"keystring\" name=\"keystring\" placeholder=\"Enter code\"></div>\n";
                        $html.="<div><input class=\"btn btn-default\" type=\"submit\" name=\"send\" value=\"Send\" style=\"width:100%;margin-top:5px;\"></div>\n";
                        $html.="<div><input class=\"btn btn-default\" type=\"submit\" name=\"updatecode\" value=\"Update code\" style=\"width:100%;margin-top:5px;\"></div>\n";
                    $html.="</td>\n<td>\n";
                        $html.="<div id=\"imgver\" style=\"margin-left:10px;\"><img style=\"\" src=\"include/image.verification/index.php".$imgverify."\" alt=\"\" /></div>\n";
                    $html.="</td>\n";
                $html.="</tr>\n</table>\n";
            $html.="</div>\n";
        $html.="</form>\n";
    $html.="</div>\n";
$html.="</div>\n";
print($html);

?>

编辑:

显然我需要10个声望来发布图片,因为我在12小时前创建了这个帐户...

邮件发送后表单的屏幕截图如下: http://nocode.se/mailform.jpg 它是瑞典语,绿色文字说&#34;邮件已发送&#34;。蓝色文字显示&#34;确认已发送给您&#34;。这些文本下的行是各自的邮件服务器响应,即我和访问者。

1 个答案:

答案 0 :(得分:0)

好的,当你检查这一行时:

$server_response=getMX($server_email,$server_subject,$server_message,$client_email,$server_headers);
if($server_response[0]){

如果你发送另一封电子邮件,那么结束时。