2013-11-15 100 views
0

我正在嘗試爲一個房地產網站建立一個聯繫表單,並且提交工作。但是,當它到達我的電子郵件地址時,出於某種原因,「租戶」和「業主」字段爲空。我錯過了什麼嗎?請參閱:PHP提交表單不發送所有字段?

<?php 
$action=$_REQUEST['action']; 
if ($action=="") /* display the contact form */ 
    { 
    ?> 
<form action="" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="action" value="submit"> 
    First & Last Name:<br> 
    <input name="name" type="text" value="" size="30"/><br> <br> 
    Your Email Address:<br> 
    <input name="email" type="text" value="" size="30"/><br> <br> 
    Tenants, please describe what you're looking for:<br> 
    <textarea name="tenants" rows="7" cols="30"></textarea><br> <br> 

    Landlords, please describe what you're looking for:<br> 
    <textarea name="landlords" rows="7" cols="30"></textarea><br> <br> 

      Additional Comments:<br /> 
     <textarea name="message"></textarea> 
     <br> 
     <center> 
    <input type="submit" value="Send email"/> </center> 
<br /></p> 
    </form> 

<?php 
    } 
else    /* send the submitted data */ 
    { 
    $name=$_REQUEST['name']; 
    $email=$_REQUEST['email']; 
    $tenants=$_REQUEST['tenants']; 
    $landlords=$_REQUEST['landlords']; 

    $message=$_REQUEST['message']; 
    if (($name=="")||($email=="")||($message=="")) 
     { 
     echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
     } 
    else{   
     $from="From: $name<$email>\r\nReturn-path: $email"; 
     $subject="Leasing Submission"; 
     mail("[email protected]", $subject, $message, $from); 
     echo "Email sent!"; 
     } 
    } 
?> 
+0

你不包括你的'郵件()' –

+0

在體內POST數據他們不爲空 - 你永遠不會把它們放在首位。 –

+0

另外,請考慮使用[適當的** header()**信息](http://php.net/manual/en/function.mail.php) –

回答

0

只是試試這個:

else    /* send the submitted data */ 
{ 
$name=$_REQUEST['name']; 
$email=$_REQUEST['email']; 
$tenants=$_REQUEST['tenants']; 
$landlords=$_REQUEST['landlords']; 

$message=$_REQUEST['message']; 
$fullmessage = " {$name}, mailaddres {$email},tenant info: {$tenants} , landlord info: {$landlords}. He gaves us the following message: {$message}"; 

if (($name=="")||($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{   
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Leasing Submission"; 
    mail("[email protected]", $subject, $fullmessage, $from); 
    echo "Email sent!"; 
    } 
} 
?> 
0

您實際上並未發送房東或租戶的數據。您將字段放入並將其分配給變量,但不會將它們附加到$ message變量,這是通過電子郵件發送的。

試着這麼做:

$tenants = $_REQUEST['tenants']; 
$landlords = $_REQUEST['landlords']; 
$message = $_REQUEST['message']; 
$message .= "\n\nLandlords: $landlords\n\nTenants: $tenants"; 
+0

假設OP使用'Content-Type:text/html'因此'\ n'或換行符會更合適。 –

+0

@ Fred-ii-無論如何,我會將它們更改爲新行,只是因爲這是默認設置。 –

+0

如果沒有標題(html)標題信息,最好使用它與OP的發佈代碼一起顯示。然後OP可能會回來說「我的電子郵件中有'
'」。這就像打開一堆蠕蟲一樣。 ;-) –

相關問題