我之前确实进行了搜索,但找不到与我遇到的问题密切相关的内容。我最近使用表单元素和 PHP 设置了一个表单到 POST 方法。我可以确认我正在接收电子邮件和其余字段的信息,但是<select>
Jquery 'datepicker' 元素没有将任何信息传递给电子邮件,它们解析为空白。
HTML代码如下:
<form method="POST" action="mail.php" id="contactform" class="centered">
<fieldset>
<input type="text" name="first_name" placeholder="First Name" required>
<div class="controls controls-row">
<input type="text" name="last_name" placeholder="Last Name" required>
</div>
<input type="email" name="email" placeholder="Email Address" required>
<div class="controls-row">
<input type="text" id="datepicker" name="check_in" placeholder="Check-in" required>
</div>
<div class="controls-row">
<input type="text" id="datepicker2" name="check_out" placeholder="Check-out" required>
</div>
<div class="controls-row">
<select id="modalselect" name="rooms">
<option value="0" selected="selected">Number of Rooms</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5+</option>
</select>
</div>
<div class="controls-row">
<select id="modalselect" name="people">
<option value="0" selected="selected">Number of People</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="1">8</option>
<option value="2">9</option>
<option value="3">10+</option>
</select>
</div>
<textarea rows="3" name="additional" input class="input-xparge" placeholder="Anything else?" class="span5"></textarea>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button type="submit" name="submit" input type="submit" form="contactform" class="btn btn-block btn-large btn-success" value="submit">Submit</button>
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['people'];
$additional = $_POST['additional'];
$from = "From: Babbacombe Hall Mailserver";
$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>';
}
}
?>
您的帮助和专业知识将不胜感激!