我非常感谢我的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 = "lloyd.rees09@bathspa.ac.uk";
$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>';
}
}
&GT;
提前谢谢你!
答案 0 :(得分:3)
你不需要在'button'标签上添加name =“submit”吗?
在你的php中,你正在测试'if($ _POST ['submit']){'
和$ _POST ['submit']可能没有在该标签中没有name =“submit”的情况下设置