gpt4 book ai didi

php - AJAX 联系表单无法发布数据

转载 作者:行者123 更新时间:2023-11-30 10:33:29 25 4
gpt4 key购买 nike

所以我得到了这个 AJAX 联系表单,我以前使用过它的代码。我不明白为什么它不起作用。

HTML
<div id="website-contact-form">
<form id="website_contact" name="website_contact">
<input id="email-address-input" name="website-email" type="text" placeholder="Your email here" class="order-form-input" /><br />
<textarea name="website-message" placeholder="Please give a brief description of what you have in mind, plus contact details." class="order-form-textarea"></textarea>
<a href="#" id="submit-website-project" name="submit-website-project" class="send-button"></a>
</form>
</div>

JS

<script type="text/javascript">
$(document).ready(function(){
$('#submit-website-project').click(function (e) {

e.preventDefault();
if ($('#email-address-input').val() != ""){

postForm("ajax/contact-website.php", "website_contact",
function (data) {

if (data == "success") {
$('#website-contact-form').
html("<br />Thankyou for your enquiry. I'll "+
"get in touch shortly.");
} else {

alert("That didn't work. Try again?");
}
});
}
});

}); //END DOCUMENT READY

function postForm(url, form_id, success_func) {
$.ajax({
type: "POST",
url: url,
data: $("#" + form_id).serialize(),
success: function (data) {
success_func(data);
}
});
}
</script>

最后是我的 PHP

<?php

if (isset($_POST['email'])) {
$_POST['email'] = trim(@$_POST['email']);

$ToEmail = 'barneywimbush:gmail.com';
$EmailSubject = 'Barneywimbush.com';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$MESSAGE_BODY = "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["project_description"])."";

$res = mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader); // or die ("Failure")

if ($res) {
echo "success";
}
else {
echo "failed";
}
}
else {
echo "failed";
}

我刚收到警告“那没用。再试一次?”

最佳答案

您的 $_POST 的 PHP 变量不正确,在检查网络面板时,您的表单正在发送,

网站邮箱: yes@test.com

网站消息:测试数据

虽然您的 PHP 代码看起来是 $_POST['email'],但它应该是 $_POST['website-email'];

更改输入元素的名称属性以更改请求的参数名称。

关于php - AJAX 联系表单无法发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15465358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com