2013-02-12 138 views
1

我非常感謝我的PHP聯繫表單的一些幫助。我已經遵循了一些教程來嘗試使這個工作,我仍然沒有運氣。代碼如下。PHP表單無法正常工作

N.B.我正在使用Twitter Bootstrap Framework中定義的樣式元素,並且窗體出現在模式樣式的彈出窗口中(儘管我看不出爲什麼會影響窗體)。

除了啓用PHP之外,還有其他任何我可能需要在主機端激活/配置的東西。

表單代碼:

<form method="POST" action="mail.php"> 
    <fieldset> 
     <input type="text" name="first_name" placeholder="First Name"> 
     <input type="text" name="last_name" placeholder="Last Name"> 
     <input type="email" name="email" placeholder="Email Address"> 
     <div class="controls controls-row"> 
     <input type="date" name="check_in" placeholder="Check in Date"><span class="help-inline">Check-in</span> 
     </div> 
     <div class="controls controls-row"> 
     <input type="date" name="check_out" placeholder="Check out Date"><span class="help-inline">Check-out</span> 
     </div> 
     <input type="number" name="rooms" min="1" max="7" placeholder="Number of Rooms"> 
     <input type="number" name="occupants" min="1" max="14" placeholder="Number of Occupants"> 
     <textarea rows="3" name="additional" input class="input-xparge" placeholder="Additional requirements" class="span5"></textarea> 
    </fieldset> 

    <div class="modal-footer"> 
     <button type="submit" input type="submit" id="submit" class="btn btn-block btn-large btn-success" value="submit">Submit</button> 
    </div> 
    </form> 

PHP代碼:

<?php 
$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$email = $_POST['email']; 
$check_in = $POST['check_in']; 
$check_out = $POST['check_out']; 
$rooms = $POST['rooms']; 
$occupants = $POST['occupants']; 
$additional = $_POST['additional']; 
$from = "From: $first_name"; 
$to = "[email protected]"; 
$subject = "New Booking Enquiry"; 

$body = "First Name: $first_name\n Last Name: $last_name\n Email: $email\n Check In: $check_in\n Check Out: $check_out\n Number of Rooms: $rooms\n Number of Occupants: $occupants\n Additional Information: $additional"; 

if ($_POST['submit']) { 
if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>'; 
    } else { 
     echo '<p>Something went wrong, go back and try again!</p>'; 
    } 
} 

>

衷心感謝你提前!

+0

你得到的錯誤/問題是什麼? – Laurence 2013-02-12 16:53:28

+0

你應該描述什麼不起作用。 – 2013-02-12 16:54:14

回答

3

你不需要添加name =「submit」到'button'標籤嗎?

在你的PHP

,你正在測試 '如果($ _ POST [' 提交 ']){'

和$ _POST [ '提交']可能沒有得到設定沒有名字在標籤= 「提交」

+0

這應該解決它。我想補充說,你應該過濾/清理你的用戶輸入。垃圾郵件發送者可以使用您的腳本以這種方式從服務器發送垃圾郵件。 – 2013-02-12 16:58:45

+0

謝謝你的幫助!訣竅了。這個社區真棒:) – 2013-02-13 09:17:33