我没有';I don’我不知道;It’联系表格有问题


I don't know what's wrong with contact form

我是web开发的新手,需要帮助处理此联系表单。我使用的是引导程序模板。

抱歉发布错误,我是新来的,我对发布和编辑有点困惑。

这是我的PHP代码:

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message']);
        // $human = intval($_POST['human']);
        $from = 'Demo Contact Form'; 
        $to = 'info@artgate.me'; 
        $subject = 'Message from Contact Demo ';
        $body = "From: $name'n E-Mail: $email'n Message:'n $message";
        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }
        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }
        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }
        //Check if simple anti-bot test is correct
        //if ($human !== 5) {
         //   $errHuman = 'Your anti-spam is incorrect';
        }
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
    }
?>

JS代码

function contactForm(){
  $('.btn-submit').on('click',function(e){
        var $this = $(this);
        e.preventDefault();
        $.ajax({
            url  : 'contact.php',
            type : 'POST',
            data : $this.closest('.contact-form').serialize(),
            success : function(data){
                if ($(data).is('.send-true')){
                    $this.addClass('loading').delay(650).queue(function(){
                        $this.addClass('success').addClass('loaded').dequeue();
                    });
                } else {
                    $this.addClass('error');
                }
                $this.delay(500).queue(function(){
                    $this.removeClass('loaded').removeClass('loading').dequeue();
                });
                $this.delay(400).queue(function(){
                    if ($(data).is('.send-true')){
                        $this.removeClass('success').closest('.contact-form').trigger('reset');
                    } else {
                        $this.removeClass('error');
                    }
                    $this.dequeue();
                });
            }
    });
  });
}

尝试从以下位置更改php:

if (isset($_POST["submit"])) {

到此:

if (isset($_POST["btn-submit"])) {

如果您将提交按钮命名为"btn-submit",那么您的POST将包含一个名为"btn-submit"的变量

在评论中,你说你的按钮的HTML代码是这样的:

<button type="submit" data-hover="Send" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>

您需要的是一个"Name"属性。所以它应该是这样的:

<button type="submit" data-hover="Send" name="sendform" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>

编辑后,您需要更改

if (isset($_POST["submit"])) {

if (isset($_POST["sendform"])) {

这应该会让它现在发挥作用。

if(isset($_POST["submit"](({

收件人if(isset($_POST["submit_button_"]({

那么我会为你工作我想