2013-08-27 30 views
0

我跟着一個簡單的教程,使這裏工作:http://estrellaprofessional.com/contact.html在PHP表單提交不會發布FIRST_NAME和姓氏

我得到除fist_name和last_name拍攝的所有值。

而且我作爲使用的代碼如下:

<?php 
$country=$_POST['country']; 
$prospect=$_POST['prospect']; 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$phone = $_POST['phone']; 
$message = $_POST['message']; 

$all= 
"email: ".$email."\r\n". 
"Contact Form Submission ".$subject."\r\n". 
"country: ".$country."\r\n". 
"prospect: ".$prospect."\r\n". 
"first_name: ".$first_name."\r\n". 
"last_name: ".$last_name."\r\n". 
"message: ".$message."\r\n"; 

    $mailheaders = "From: $email\r\n"; 
    $mailheaders .= "To: [email protected]\r\n"; 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1\n"; 
     mail($toaddress, $subject, $all, $mailheaders); 
      echo("Thank you $name for your interest in Estrella Professional. Someone 

from Estrella Professional will be in contact with you soon. Feel free to continue to browse the site."); 
     die; 
?> 

作爲一個小白我不知道我做錯了什麼?有人指出我正確的方向。 在此先感謝!

+2

什麼是你的HTML表單的樣子喜歡? – Fluffeh

+0

是的,@Fluffeh說的也是,請給我們輸出:'echo print_r($ _ POST);'在你的表單被髮送後(把這個代碼放在你向我們提問的文件中)。 –

+0

而不是爲$ _POST對象的每個單一輸入賦值,您可能更好地使用foreach循環,因爲對於大量的字段,您將很難用這種方式管理它們,例如if(!empty($ _ POST)){ foreach($ _POST,作爲$ input_name => $ input_value){$$ input_name = $ input_value; }} – sven

回答

2

根據我在鏈接中可以看到的HTML代碼,您沒有在表格中輸入first_namelast_name的字段。您只需具備以下條件:

<input name="name" type="text" style="width: 98%;" class="input-text" /> 
<br /> 

因此,無論使用:

$name = $_POST['name']; 

或者在您的形式兩個字段叫做first_namelast_name這樣的:

<label>Given Name*</label> 
<input name="first_name" type="text" style="width: 98%;" class="input-text" /> 
<br /> 
<label>Surname*</label> 
<input name="last_name" type="text" style="width: 98%;" class="input-text" /> 
<br /> 
+0

哦,我的天啊!得到它修復。謝謝! – Aroganz