-1
我遇到的問題是我創建的表單我確定我缺少一些簡單的東西,因爲某些原因它不會將電話號碼發送到所有其他電子郵件字段被髮送並在emai中輸出。我有一個我創建的網絡表單的問題
HTML表單低於:
<div class="form-wrapper">
<p id="success"></p>
<form id="contact-form" name="contact-form" method="POST">
<label class="label">Name:</label>
<p><input type="text" value="" name="contact-names" class="contact-names"/><span class="name-required"></span></p>
<label class="label">Email:</label>
<p><input type="text" value="" name="contact-email" class="contact-email"/><span class="email-required"></span></p>
<label class="label">Phone:</label>
<p><input type="text" value="" name="contact-phone" class="contact-phone"/><span class="phone-required"></span></p>
<label class="label">Message</label>
<p>
<textarea class="contact-commnent" name="comments">
</textarea><span class="comment-required"></span></p>
<label class="label"></label>
<p id="p-submit">
<input id="submit-form" class="submit-button" name="submit"type="submit" value="Submit"></p>
</form>
</div>
的JavaScript是:
$('#submit-form').click(function(){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var names = $('#contact-form [name="contact-names"]').val();
var email_address = $('#contact-form [name="contact-email"]').val();
var phone = $('#contact-form [name="contact-phone"]').val();
var comment = $.trim($('#contact-form .contact-commnent').val());
var data_html ='' ;
if(names == ""){
$('.name-required').html('Your name is required.');
}else{
$('.name-required').html('');
}
if(email_address == ""){
$('.email-required').html('Your email is required.');
}else if(reg.test(email_address) == false){
$('.email-required').html('Invalid Email Address.');
}else{
$('.email-required').html('');
}
if(phone == ""){
$('.phone-required').html('Your Phone Number is required.');
}else{
$('.phone-required').html('');
}
if(comment == ""){
$('.comment-required').html('Comment is required.');
}else{
$('.comment-required').html('');
}
if(comment != "" && names != "" && reg.test(email_address) != false){
data_html = "names="+ names + "&comment=" + comment + "&email_address="+ email_address;
//alert(data_html);
$.ajax({
type: 'POST',
url: 'contact-send.php',
data: data_html,
success: function(msg){
if (msg == 'sent'){
$('#success').html('Your Message Has Been Sent We Will Be In Touch Soon') ;
$('#contact-form [name="contact-names"]').val('');
$('#contact-form [name="contact-email"]').val('');
$('#contact-form [name="contact-phone"]').val('');
$('#contact-form .contact-commnent').val('');
}else{
$('#success').html('Mail Error. Please Try Again.!') ;
}
}
});
}
return false;
});
的PHP是:
<?php
$names = $_POST['names'];
$email = $_POST['email_address'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$to ='EMAIL ADDRESS GOES HERE REMOVED';
$message = "";
$message .= "Name: " . htmlspecialchars($names, ENT_QUOTES) . "<br>\n";
$message .= "Email: " . htmlspecialchars($email, ENT_QUOTES) . "<br>\n";
$message .= "Phone: " . htmlspecialchars($phone, ENT_QUOTES) . "<br>\n";
$message .= "Message: " . htmlspecialchars($comment, ENT_QUOTES) . "<br>\n";
$lowmsg = strtolower($message);
$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: \"" . $names . "\" <" . $email . ">\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$message = utf8_decode($message); mail($to, "Note from the Contact Form", $message, $headers);
if ($message){
echo 'sent';
}else{
echo 'failed';
}
?>
如果有人能看到的東西我有錯過了我會很g有成效的我一直在看這個很長時間,看不到我缺少的東西。
當你調試這個,在哪個步驟丟失的值? JavaScript是否成功將它們添加到請求中?請求在發送到服務器時是否包含它們?服務器代碼在撰寫電子郵件之前是否看到它們?您可以通過調試將其縮小很多。 – David