我非常接近完成这个小项目,我需要做的就是让我的联系表格发送电子邮件。容易吗?没有.lol
我在提交邮件后收到联系表单但是没有发送电子邮件,并且想知道是否有人可以帮我这个?我的代码如下:
http://madaxedesign.co.uk/dev/contact.php http://madaxedesign.co.uk/dev/
Jquery的: var doSubmit = function(event){ var postData = jQuery('#submit_message')。serialize();
jQuery.ajax({
type: "POST",
url: '/dev/contact.php',
data: postData
}).done(function( html ) {
alert(html);
});
event.preventDefault();
};
$(function () {
$('#submit_message').submit(doSubmit);
});
PHP:
<?php
$your_email = "maxlynn@madaxedesign.co.uk";
$subject = "Email From Madaxe";
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
$thankyou_message = "<p>Thank you. Your message has been sent. We Will reply as soon as possible.</p>";
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
?>
<form id="submit_message" class="hide_900">
<div id="NameEmail">
<div>
<label for="txtName">Name*</label>
<input type="text" title="Enter your name" name="txtName" />
</div>
<div>
<label for="txtEmail">Email*</label>
<input type="text" title="Enter your email address" name="txtEmail" />
</div>
</div>
<div id="MessageSubmit">
<div>
<textarea maxlength="1200" title="Enter your message" name="txtMessage"></textarea>
<label for="txtMessage">Message</label>
</div>
<div class="submit">
<input type="submit" value="Submit" /></label>
</div>
</div>
</form>
<?php
}
elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;
}
else {
$referer = $_SERVER['HTTP_REFERER'];
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL, nice hacking attempt ;p.";
exit;
}
mail($your_email, $subject, $message, "From: $name <$email>");
echo $thankyou_message;
}
?>
感谢您的帮助
答案 0 :(得分:1)
您应该调试代码以查看是否有任何错误或错误,然后在您的问题中包含错误以获得更好的帮助。但无论如何,通过快速浏览,你的jQuery中缺少一个分号:
jQuery.ajax({
url: '/contact.php',
data: postData
}).done(function (html) {
alert(html);
});
event.preventDefault();
}; // <-- HERE
您的HTML格式不正确:
<div class="submit">
<input type="submit" value="Submit" /></label> <!-- HERE the `label` -->
</div>
检查这两个并报告回来。我担心这不会解决你的问题,但值得尝试。
<强>更新强>
将此添加到您的jQuery:
jQuery.ajax({
type: "POST", // THIS
url: '/contact.php',
data: postData
...
答案 1 :(得分:0)
使用新的PHP并取出我自己的Jquery,现在必须找到一种方法在弹出窗口中重定向感谢信息。 谢谢你的帮助Sam