我的联系表格不起作用

时间:2015-10-10 01:32:19

标签: javascript php jquery contact

我有这个联系表格。当我按下提交按钮时,它只是重新加载漏洞网页而不发送任何内容。它甚至不显示成功或错误消息。请帮帮我。 有我的代码:

$(document).ready(function(){
    
  $('#contactform').on('submit',function(e) {

    $.ajax({
      url:'action.php',
      data:$(this).serialize(),
      type:'POST',
      success:function(data){
        console.log(data);
        $(".success").show().fadeOut(5000);
      },
      error:function(data){ $(".error").show().fadeOut(5000); }
      });
    e.preventDefault();
  });
  
});

**<!-- This is php code: -->**

<?php

	$firstname	=	$_POST['firstname'];
	$lastname   =	$_POST['lastname'];
	$email	    =	$_POST['email'];
	$message    =   $_POST['message'];
	
	$to = 'kissa101295@gmail.com';
	$subject = 'Contact Form';
	$msg = "First Name: $firstname\nLast Name: $lastname\nEmail: $email\message: $message";
	mail($to, $firstname, $msg);

?>
<form class="contactform" action="action.php" method="POST" name="contactform" id="contactform">

        <div class="errorwrap">
          <div class="error">Error!</div>
          <div class="success">Submitted!</div>
        </div>

        <div class="input-fields">
          <label>First Name: </label>
          <input class="text" type="text" name="firstname" id="firstname" required />
        </div>

        <div class="input-fields">
          <label>Last Name: </label>
            <input class="text" type="text" name="lastname" id="lastname" required />
        </div>

        <div class="input-fields">
          <label>Email: </label>
            <input class="text" type="text" name="email" id="email" required />
        </div>

        <div class="input-fields">
          <label> Message:</label>
            <textarea name="message" placeholder="Write me a message here..."></textarea>
        </div>

        <div class="buttons">
          <input type="submit" value="Submit" />
        </div>

      </form>

1 个答案:

答案 0 :(得分:1)

我认为你的问题是函数中的标题值:

尝试使用此标头参数添加此标头:

$headers = 'From: example@example.com' . "\r\n" .
    'Reply-To: example@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $firstname, $message, $headers);

参考: