init
This commit is contained in:
65
mail/contact.js
Normal file
65
mail/contact.js
Normal file
@@ -0,0 +1,65 @@
|
||||
$(function () {
|
||||
|
||||
$("#contactForm input, #contactForm textarea").jqBootstrapValidation({
|
||||
preventSubmit: true,
|
||||
submitError: function ($form, event, errors) {
|
||||
},
|
||||
submitSuccess: function ($form, event) {
|
||||
event.preventDefault();
|
||||
var name = $("input#name").val();
|
||||
var email = $("input#email").val();
|
||||
var subject = $("input#subject").val();
|
||||
var message = $("textarea#message").val();
|
||||
|
||||
$this = $("#sendMessageButton");
|
||||
$this.prop("disabled", true);
|
||||
|
||||
$.ajax({
|
||||
url: "contact.php",
|
||||
type: "POST",
|
||||
data: {
|
||||
name: name,
|
||||
email: email,
|
||||
subject: subject,
|
||||
message: message
|
||||
},
|
||||
cache: false,
|
||||
success: function () {
|
||||
$('#success').html("<div class='alert alert-success'>");
|
||||
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
|
||||
.append("</button>");
|
||||
$('#success > .alert-success')
|
||||
.append("<strong>Your message has been sent. </strong>");
|
||||
$('#success > .alert-success')
|
||||
.append('</div>');
|
||||
$('#contactForm').trigger("reset");
|
||||
},
|
||||
error: function () {
|
||||
$('#success').html("<div class='alert alert-danger'>");
|
||||
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
|
||||
.append("</button>");
|
||||
$('#success > .alert-danger').append($("<strong>").text("Sorry " + name + ", it seems that our mail server is not responding. Please try again later!"));
|
||||
$('#success > .alert-danger').append('</div>');
|
||||
$('#contactForm').trigger("reset");
|
||||
},
|
||||
complete: function () {
|
||||
setTimeout(function () {
|
||||
$this.prop("disabled", false);
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
},
|
||||
filter: function () {
|
||||
return $(this).is(":visible");
|
||||
},
|
||||
});
|
||||
|
||||
$("a[data-toggle=\"tab\"]").click(function (e) {
|
||||
e.preventDefault();
|
||||
$(this).tab("show");
|
||||
});
|
||||
});
|
||||
|
||||
$('#name').focus(function () {
|
||||
$('#success').html('');
|
||||
});
|
||||
20
mail/contact.php
Normal file
20
mail/contact.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
if(empty($_POST['name']) || empty($_POST['subject']) || empty($_POST['message']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
http_response_code(500);
|
||||
exit();
|
||||
}
|
||||
|
||||
$name = strip_tags(htmlspecialchars($_POST['name']));
|
||||
$email = strip_tags(htmlspecialchars($_POST['email']));
|
||||
$m_subject = strip_tags(htmlspecialchars($_POST['subject']));
|
||||
$message = strip_tags(htmlspecialchars($_POST['message']));
|
||||
|
||||
$to = "info@example.com"; // Change this email to your //
|
||||
$subject = "$m_subject: $name";
|
||||
$body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\n\nEmail: $email\n\nSubject: $m_subject\n\nMessage: $message";
|
||||
$header = "From: $email";
|
||||
$header .= "Reply-To: $email";
|
||||
|
||||
if(!mail($to, $subject, $body, $header))
|
||||
http_response_code(500);
|
||||
?>
|
||||
1
mail/jqBootstrapValidation.min.js
vendored
Normal file
1
mail/jqBootstrapValidation.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user