【发布时间】:2015-05-18 15:23:16
【问题描述】:
我的 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;
});
【问题讨论】:
-
$headers 是在哪里定义的?另外,能否提供一下JS,以防万一不正确?
-
好吧,在 JS 中,您会得到 ID 为 t_message 和 t_email 的输入,但 HTML 中的 id 是 d_email 和 d_message。
-
谢谢,这只是我帖子中的复制/粘贴错误。发帖前应该重读一遍。
-
没有定义 $headers。不认为我需要它,也是为了简单地查明错误。
标签: php zurb-foundation-5