My Foundation 5联系表单由于某种原因返回空白电子邮件。 javascript是正确的但我看不出我的PHP文件有什么问题。我究竟做错了什么?这是PHP:
<?php
$name = $_POST["t_name"];
$email = $_POST["t_email"];
$message = $_POST["t_message"];
$msg = "
Name: $name
Email: $email
Commments:
$message
";
$to = "me@me.com";
$subject = "From My Site";
$message = $msg;
mail($to,$subject,$message,$headers);
?>
HTML:
<div id="contactForm" class="large-6 large-offset-6 columns">
<form id="t-contact-form" method="post" data-abide="ajax">
<small class="error">Your full name is required.</small>
<input name="t_name" id="t_name" type="text" placeholder="Full Name" required>
<small class="error">An email address is required.</small>
<input name="t_email" id="d_email" type="email" placeholder="username@address.com" required>
<small class="error">Your message is required.</small>
<textarea name="t_message" id="d_message" placeholder="Enter your message here" required></textarea>
<button class="contact-submit submit">Submit</button>
</a>
</form>
</div>
和js:
$('#t-contact-form').on('valid.fndtn.abide', function() {
var t_name = $("input#t_name").val();
var t_email = $("input#t_email").val();
var t_message = $("textarea#t_message").val();
// Data for response
var dataString = 'name=' + t_name +
'&email=' + t_email +
'&message=' + t_message;
//Begin Ajax Call
$.ajax({
type: "POST",
url: "assets/php/t-mail.php",
data: dataString,
success: function() {
$('#t-contact-form').html("<div id='success'></div>");
$('#success').html("<h2>Thanks!</h2>")
.append("<p>Dear" + t_name + "!, I look forward to working with you.</p>")
.hide()
.fadeIn(1500);
},
}); //ajax call
return false;
});
答案 0 :(得分:1)
使用name
而不是t_name
发送的AJAX呼叫,email
和message
的呼叫相同。它最初在HTML中命名的方式对PHP来说并不重要,只有发布的数据很重要。
var dataString = 'name=' + t_name +
'&email=' + t_email +
'&message=' + t_message;
所以在PHP中你应该做
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
此外,您通过ID获取输入,但使用JavaScript中的名称。将它们重命名为HTML中的t_email
和t_message
,或修改JavaScript。
<input name="t_email" id="t_email" type="email" placeholder="username@address.com" required>
<textarea name="t_message" id="t_message" placeholder="Enter your message here" required></textarea>
答案 1 :(得分:0)
在js 在第三行将#t_email更改为#d_email,它将起作用