Last active
October 19, 2016 09:45
-
-
Save matdombrock/5403396ac7667295daa6 to your computer and use it in GitHub Desktop.
Dead Simple Ajax Contact Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$('#submit').click(function(){ | |
$.post("send.php", $("#mycontactform").serialize(), function(response) { | |
$('#success').html(response); | |
//$('#success').hide('slow'); | |
}); | |
return false; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form action="" method="post" id="mycontactform" > | |
<label for="name">Name:</label><br /> | |
<input type="text" name="name" id="name" /><br /> | |
<label for="email">Email:</label><br /> | |
<input type="text" name="email" id="email" /><br /> | |
<label for="message">Message:</label><br /> | |
<textarea name="message" id="message"></textarea><br /> | |
<input type="button" value="send" id="submit" /><div id="success" style="color:red;"></div> | |
</form> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = $_POST['name']; | |
$email = $_POST['email']; | |
$message = $_POST['message']; | |
$to = '[email protected]'; | |
$subject = 'the subject'; | |
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message; | |
$headers = 'From: [email protected]' . "\r\n"; | |
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
mail($to, $subject, $message, $headers); | |
echo "Your email was sent!"; | |
}else{ | |
echo "Invalid Email, please provide an correct email."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment