私はこの小さなプロジェクトの完成に非常に近づいており、私がする必要があるのは、連絡先フォームにメールを送信することだけです. 簡単ですよね?いいえ笑
メッセージが送信された後に連絡先フォームを閉じるようにしましたが、メールを送信しません。私のコードは以下の通りです:
http://madaxedesign.co.uk/dev/contact.php http://madaxedesign.co.uk/dev/
Jquery: var doSubmit = 関数 (イベント) { 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;
}
?>
ご協力いただきありがとうございます