The JavaScript
jQuery(function($){
$("#contact").submit(function(){
//grab form values before blowing it out of the DOM in the next line
values=$(this).serialize();
$("#contact").html( "<p>Sending message...</p>\n" );
//send the values to the PHP handler
$.ajax({
type: "POST",
url: $("#contact").attr('action'),
data: values,
success: function(re){
$("#contact").html(re);
}
});
return false;
});
});
PHP
<?php
if( $_SERVER["REQUEST_METHOD"] == "POST" ){
$to = "orgnsm@orgnsm.org";
$subject = "Contact through website";
$message = "Message: ".$_POST["message"]."\r\rFrom: ".$_POST["nombre"]."\r\rEmail: ".$_POST["email"];
$from = $_POST["email"];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo( "<p>Your message has been sent. Thank you</p>\n" );
}
?>
HTML
<form action="/sites/all/themes/visionarysports/contact.php" method="POST" id="contact">
<div><input type="text" name="nombre" id="nombre" placeholder="Your Name"/></div>
<div><input type="email" name="email" id="email" placeholder="Your E-mail"/></div>
<div><textarea name="message" id="message" placeholder="Your Message"></textarea></div>
<div><input type="submit" value="Send"/></div>
</form>