вот то что тебе нужно на ajax
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/style1.css">
<link rel="stylesheet" type="text/css" media="all" href="fancybox/jquery.fancybox.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="fancybox/jquery.fancybox.js?v=2.0.6"></script>
</head>
<body>
<div id="wrapper">
<p><a class="button modalbox" href="#inline">Contact Me</a></p>
</div>
<div id="inline" style="display:none">
<form id="contact" name="contact" action="#" method="post">
<label for="email"><span class="required">*</span> Email</label>
<input name="email" type="email" id="email" class="txt" />
<label for="comments"><span class="required">*</span> Твой комментарий</label>
<textarea name="msg" id="msg"></textarea>
<button id="send" class="button">Отправить</button>
</form>
</div>
</body>
</html>
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() {
return false;
});
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
if (mailvalid == false) {
$("#email").addClass("error");
}
$("#email").change(function() {
$("#email").removeClass("error");
});
if (msglen < 4) {
$("#msg").addClass("error");
}
$("#msg").change(function() {
$("#msg").removeClass("error");
});
if (mailvalid == true && msglen >= 4) {
$("#send").replaceWith("<em>отправляется...</em>");
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Спасибо! Ваше сообщение отправлено.</strong></p>");
setTimeout("$.fancybox.close()", 2000);
});
}
}
});
}
});
});
содержание файла sendmessage.php
<?php
$sendto = "test@yandex.ru";
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
$subject = "Message from your site";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Message from your site</h2>\r\n";
$msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(@mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>