2014-01-20 67 views
0

對不起,作爲一個noob,但我盡我所能。我已經完成並閱讀了所有我能找到的東西,而且我從來沒有這樣做過。真的很感激幫助。表單ID匹配html和javascript。 PHP在Javascript中被鏈接,並且我的html鏈接在頭部。我錯過了什麼?我嘗試了其他代碼,我也在網上找到,也沒有任何內容。問題是沒有電子郵件通過發送。如果你點擊發送頁面重新加載和多數民衆贊成它。阿賈克斯聯繫表不發送電子郵件

<!--[if lte IE 8]> 
<script src="js/html5shiv.js"></script><![endif]--> 

<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
<script src="js/jquery.min.js"></script> 
<script src="js/jquery.dropotron.js"></script> 
<script src="js/skel.min.js"></script> 
<script src="js/skel-panels.min.js"></script> 
<script src="js/init.js"></script> 
<script src="js/contact.js"></script> 
<noscript> 
    <link rel="stylesheet" href="css/skel-noscript.css" /> 
    <link rel="stylesheet" href="css/style.css" /> 
    <link rel="stylesheet" href="css/style-noscript.css" /> 
</noscript> 


<!-- Contact Form--> 
<div class="content style4 featured"> 
<div class="container small"> 
    <form id="contact" form method="post"> 

    <div class="row half"> 
     <div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div> 
     <div class="6u"><input type="text" class="text" placeholder="Email" name="email" /></div> 
    </div> 

    <div class="row half"> 
     <div class="12u"><textarea name="text" placeholder="Message"></textarea></div> 
    </div> 

    <div class="row"> 
     <div class="12u"> 
      <ul class="actions"> 
       <li><input type="submit" class="button" value="Send Message" /></li> 
       <li><input type="reset" class="button alt" value="Clear Form" /></li> 
<p class="success" style="display:none">Your message has been sent successfully.</p> 
       <p class="error" style="display:none">E-mail must be valid and message must be longer than 100 characters.</p> 
      </ul> 
     </div> 

    </div> 

    </form> 
</div> 
</div> 

PHP:

<?php 
    // Email Submit 
    // Note: filter_var() requires PHP >= 5.2.0 
    if (isset($_POST['email']) && isset($_POST['name']) && isset($_POST['text']) &&  filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { 
     // detect & prevent header injections 
     $test = "/(content-type|bcc:|cc:|to:)/i"; 
     foreach ($_POST as $key => $val) { 
      if (preg_match($test, $val)) 
      exit; 
     } 

     //send email 
     mail("[email protected]", "Contact Form: ".$_POST['name'], $_POST['text'], "From:" .  $_POST['email']); 
    } 
?> 

JS:

$('#contact').submit(function() { 
    var name = $("#name").val(); 
    var email = $("#email").val(); 
    var message = $("#message").val(); 
    var dataString = 'name=' + name + '&email=' + email + '&message=' + message; 

    $.ajax({ 
     type : "POST", 
     url : "mail.php", 
     data : dataString, 
     cache : false, 
     success : function() {    
      $("#contact").fadeOut(300); 
           $("#notice").fadeIn(400); 
     } 
    }); 
    return false; 
}); 

感謝。

+1

請不要使用相同的內容創建多個問題..如果您沒有得到正確的答案,請稍等.. http://stackoverflow.com/questions/21229195/ajax -contact-form-problems-no-email-being-sent?rq = 1 –

回答

0

嘗試preventing the default form submission改變:

$('#contact').submit(function() { 
... 

$('#contact').submit(function(evt) { 
    evt.preventDefault(); 
    //rest of your js code 

,你不要有id爲nameemailmessage輸入元素按您發佈的代碼。將這些添加爲您的輸入元素的ID

+0

在服務器端更改。儘管如此,似乎還沒有改變。 – user3214277

+0

對不起,但我不確定哪些行是輸入元素? – user3214277