PHP表单消息确认

时间:2017-04-12 14:18:50

标签: php forms confirmation

我已经掌握了有关此表单的所有信息,除非邮件未发送,用户不会转到“未发送邮件”页面。

如果用户正确填写表单,一切正常 - 发送和接收邮件,用户转到“已发送邮件”确认页面。

所以我在消息验证的else部分做错了。

有人能看到我做错了吗?

    <?php
if(isset($_POST['submit'])):
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
        //your site secret key
        $secret = 'Secret key goes here';
        //get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);

        $name = !empty($_POST['name'])?$_POST['name']:'';
        $email = !empty($_POST['email'])?$_POST['email']:'';
        $message = !empty($_POST['message'])?$_POST['message']:'';
        if($responseData->success):
            //contact form submission code
                $to = 'me@myplace.com';
            $subject = 'Website Enquiry';
            $htmlContent = "
                <h1>Website Booking Request</h1>
                <p><b>Name: </b>".$name."</p>
                <p><b>Email: </b>".$email."</p>
                <p><b>Message: </b>".$message."</p>
            ";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            // More headers
            $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";
            //send email
            @mail($to,$subject,$htmlContent,$headers);
     print "<meta http-equiv=\"refresh\" content=\"0;URL=messagesent.html\">";
            $name = '';
            $email = '';
            $message = '';
        else:
           print " <meta http-equiv=\"refresh\" content=\"0;URL=messagenotsent.html\">";

?>

0 个答案:

没有答案