Last active
March 14, 2018 11:29
-
-
Save srokatonie/2ad28ed52b7267a9ec348ef3ff56b7ed to your computer and use it in GitHub Desktop.
PHP Mail function
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
<script> | |
function submitForm() { | |
// Initiate Variables With Form Content | |
var name = $("#name").val(); | |
var email = $("#email").val(); | |
var msg_subject = $("#msg_subject").val(); | |
var message = $("#message").val(); | |
$.ajax({ | |
type: "POST", | |
url: "php/contact.php", | |
data: "name=" + name + "&email=" + email + "&message=" + message, | |
success: function(text) { | |
if (text == "success") { | |
// show success on front end | |
console.log("Form success"); | |
} else { | |
// show error on front end | |
console.log("Form error"); | |
} | |
} | |
}); | |
} | |
</script> | |
<?php | |
$to = '[email protected]'; | |
$subject = 'Contact form'; | |
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])){ | |
$name = $_POST['name']; | |
$email = $_POST['email']; | |
$message = $_POST['message']; | |
$headers = "From: $name\r\nReply-to: $email"; | |
if (@mail($to, $subject, $message, $headers)) { | |
echo "success"; | |
} else { | |
echo "Something went wrong. Please try again later."; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment