2012-08-27 38 views
1

好吧,我有一個表單使用PHP發送郵件到一個電子郵件地址。我還有一個jQuery/AJAX部分,可以在不重新加載頁面的情況下驗證表單並執行PHP。出於某種原因,利息下的產品利息價值下降不在電子郵件中。我錯過了什麼?我一直在用這個讓自己瘋狂。謝謝!PHP/AJAX郵件聯繫表 - 電子郵件的一部分沒有顯示

這是形式:

 <div class="contact-form"> 
      <div class="row"> 
        <div class="field"><input type="text" id="first" name="first" class="input" placeholder="First Name"></div> 
        <div class="field"><input type="text" id="last" name="last" class="input" placeholder="Last Name"></div> 
        <div class="field"><input type="text" id="telephone" name="telephone" class="input" placeholder="Phone Number"></div> 
      </div> 
      <div class="row"> 
        <div class="field"><input type="email" id="email" name="email" class="input" placeholder="E-mail"></div> 
        <div class="field"> 
             <select class="select" name="interest" id="interest"> 
              <optgroup label="Countwise Products:"> 
                <option value="I-Count">I-Count</option> 
                <option value="Q-Count">Q-Count</option> 
                <option value="D-Count">D-Count</option> 
                <option value="Z-Count">Z-Count</option> 
              </optgroup> 
             </select> 
        </div> 
        <input type="submit" value="Get Better Results!" class="button3 dark-blue submit"/> 
        <span class="error" style="display:none">All Fields Are Required!</span> 
        <span class="success" style="display:none">Contact Form Submitted Successfully</span> 
      </div> 
     </div> 


    </form> 

這是名爲header_form_email.php的PHP

<?php 

// POST Variables 
//Name 
$first = $_POST['first']; 
$last = $_POST['last']; 
//Phone 
$telephone = $_POST['telephone']; 
//E-mail 
$email = $_POST['email']; 
//Interest 
$interest= $_POST['interest']; 

// Contact subject 
$subject = "CountWise Website - Sales Request"; 

$name = "$first" . " " . "$last"; 



$message = "You have received a new information request from Countwise.com\n". 
"Name: " . "$name\n". 
"Phone: " . "$telephone\n". 
"Email: " . "$email\n". 
"Product Interest: " . "$interest"; 

// From 
$mailheader = "From: $email \r\n"; 

// Enter your email address 
$to ="[email protected]"; 

$send_contact=mail($to,$subject,$message,$mailheader); 

// Check, if message sent to your email 
if($send_contact){ 
echo "<strong>We have received your information and will be in contact you shortly. Thank you.</strong>" ; 
} 
else { 
echo "ERROR"; 
} 
?> 

這是AJAX

$(function() { 
    $(".submit").click(function() { 
     var first = $("#first").val(); 
     var last = $("#last").val(); 
     var telephone = $("#telephone").val(); 
     var email = $("#email").val(); 
     var interest = $("#interest").val(); 
     var dataString = 'first=' + first + '&last=' + last + '&telephone=' + telephone + '&email=' + email + '&interest' + interest; 

     if (first == '' || last == '' || telephone == '' || email == '') { 
      $('.success').fadeOut(200).hide(); 
      $('.error').fadeOut(200).show(); 
     } 
     else { 
      $.ajax({ 
       type: "POST", 
       url: "http://www.drastikdesigns.com/clients/countwise/php/header_form_email.php", 
       data: dataString, 
       success: function() { 
        $('.success').fadeIn(200).show(); 
        $('.error').fadeOut(200).hide(); 
       } 
      }); 
     } 
     return false; 
    }); 
}); 

回答

4

你忘了等號:

'&interest=' + interest; 

在一個側面說明,爲什麼不只是做:

data:$("#formid").serialize(), 

,將節省您大量的時間和頭痛。第二點,使用firebug /開發工具/ chrome肯定有助於查看通過ajax發送的頭文件。

+0

啊,你是救命恩人!老實說,我不知道我在jQuery,AJAX或PHP方面做了什麼。我現在正在學習JavaScript。所以我不知道序列化是什麼或者爲什麼它會更好。 –

+0

@KellyTaylor別擔心。我們都去過那兒。只要看看它上面的文檔,你就會看到它是如何工作的,以及它如何幫你避免製作數據字符串/對象。 –

相關問題