我的部分联系信息实际上是收到我的电子邮件。 有什么原因吗? 这是HTML:
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group form-group">
<div class="controls">
<label>Full Name:</label>
<input type="text" class="form-control" id="name" name='name'>
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Phone Number:</label>
<input type="text" class="form-control" id="phone" name='phone'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Email Address:</label>
<input type="email" class="form-control" id="email" name='email'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Best way for us to reach back to you:</label>
<input type="text" class="form-control" id="reach" name='reach'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Type of event: (ex. sports/wedding/business) </label>
<input type="text" class="form-control" id="event" name='event'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Date or Weekend Desired (ex. 4/16-4/25) </label>
<input type="text" class="form-control" id="date" name='date'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Number of Attendees:</label>
<input type="text" class="form-control" id="attendees" name='attendees'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Overnight Guests</label>
<input type="text" class="form-control" id="overnight" name='overnight'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Meals Included? (Yes/No/Maybe)</label>
<input type="text" class="form-control" id="meals" name='name'>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Additional Information:</label>
<textarea rows="10" cols="100" class="form-control" id="message" name='name' maxlength="39999" style="resize:none"></textarea>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
我的Javascript是:
$(function() {
$("#contactForm input,#contactForm textarea").jqBootstrapValidation({
preventSubmit: true,
submitError: function($form, event, errors) {
// something to have when submit produces an error ?
// Not decided if I need it yet
},
submitSuccess: function($form, event) {
event.preventDefault(); // prevent default submit behaviour
// get values from FORM
var name = $("input#name").val();
var phone = $("input#phone").val();
var email = $("input#email").val();
var name = $("input#reach").val();
var name = $("input#date").val();
var name = $("input#attendees").val();
var name = $("input#overnight").val();
var name = $("input#name").val();
var message = $("textarea#message").val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
firstName = name.split(' ').slice(0, -1).join(' ');
}
$.ajax({
url: "./bin/contact_me.php",
type: "POST",
data: {
name: name,
phone: phone,
email: email,
message: message
},
cache: false,
success: function() {
// Success message
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-success')
.append("<strong>Your message has been sent. </strong>");
$('#success > .alert-success')
.append('</div>');
//clear all fields
$('#contactForm').trigger("reset");
},
error: function() {
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-danger').append("<strong>Sorry " + firstName + " it seems that my mail server is not responding...</strong> Could you please email me directly to <a href='mailto:noah@webberd.com?Subject=Message_Me from myprogrammingblog.com;>noah@webberd.com</a> ? Sorry for the inconvenience!");
$('#success > .alert-danger').append('</div>');
//clear all fields
$('#contactForm').trigger("reset");
},
})
},
filter: function() {
return $(this).is(":visible");
},
});
$("a[data-toggle=\"tab\"]").click(function(e) {
e.preventDefault();
$(this).tab("show");
});
});
/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
$('#success').html('');
});
,我的PHP就在这里:
$message = "Name: " . $_POST['name'];
$message .= "\r\nPhone " . $_POST['phone'];
$message .= "\r\nEmail: " . $_POST['email'];
$message .= "\r\nRequested Form of Contact: " . $_POST['reach'];
$message .= "\r\nEvent Type: " . $_POST['event'];
$message .= "\r\nRequested Dates: " . $_POST['date'];
$message .= "\r\nNumber of Attendees: " . $_POST['attendees'];
$message .= "\r\nOvernight Guests: " . $_POST['overnight'];
$message .= "\r\nMeals Included?: " . $_POST['meals'];
$message .= "\r\nAdditional Information: " . $_POST['message'];
$to = 'noahman2343@gmail.com';
$email_subject = "Wahnee Events Inquiry";
$email_body = $message;
$headers = "From: inquiry@wahneeevents.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
非常感谢 - 奇怪的问题 - 在这里搜索,但这是一个奇怪的问题。 任何帮助的人 - 非常感谢!!
答案 0 :(得分:0)
您需要添加更多数据:
data: {
name: name,
phone: phone,
email: email,
message: message
},
像:
$.ajax({
url: "./bin/contact_me.php",
type: "POST",
data: {
name: name,
phone: phone,
email: email,
message: message,
reach: reach,
date: date,
attendees: attendees,
overnight: overnight
},
...
此处也正确获取值:
var name = $("#name").val(),
phone = $("#phone").val(),
email = $("#email").val(),
message = $("#message").val(),
reach = $("#reach").val(),
date = $("#date").val(),
attendees = $("#attendees").val(),
overnight = $("#overnight").val();