我非常接近完成这个小项目,我需要做的就是让我的联系表发送电子邮件。容易吧?不好笑
提交消息后,我已经关闭了联系表格,但没有发送电子邮件,想知道是否有人可以帮助我解决这个问题?我的代码如下:
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;
}
?>
谢谢你的帮助