-
-
Save ArRolin/4f399da84918907625c9ae5e77107fd0 to your computer and use it in GitHub Desktop.
mail ajax
This file contains hidden or 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
/*mail*/ | |
.cf-msg { | |
padding: 10px; | |
text-align: center; | |
margin-bottom: 30px; | |
} | |
.cf-msg p { | |
margin-bottom: 0; | |
font-size: 16px; | |
font-weight: 400; | |
line-height: 24px; | |
letter-spacing: 0; | |
color: #fff; | |
text-transform: capitalize; | |
} |
This file contains hidden or 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
<div class="cf-msg"></div> | |
<form action="mail.php" method="post" id="cf"> | |
<div class="row"> | |
<div class="col-md-6 col-sm-6 col-xs-12"> | |
<input type="text" placeholder="Name" id="fname" name="fname"> | |
</div> | |
<div class="col-md-6 col-sm-6 col-xs-12"> | |
<input type="text" placeholder="Email" id="email" name="email"> | |
</div> | |
<div class="col-md-12 col-sm-12 col-xs-12"> | |
<input type="text" placeholder="Subject" id="subject" name="subject"> | |
</div> | |
<div class="col-md-12 col-sm-12 col-xs-12"> | |
<textarea class="contact-textarea" placeholder="Message" id="msg" name="msg"></textarea> | |
</div> | |
<div class="col-md-12 col-sm-12 col-xs-12"> | |
<button id="submit" class="cont-submit btn-contact" name="submit">SEND MESSAGE</button> | |
</div> | |
</div> | |
</form> |
This file contains hidden or 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
/*--------------------- | |
// Ajax Contact Form | |
--------------------- */ | |
$('.cf-msg').hide(); | |
$('form#cf button#submit').on('click', function() { | |
var fname = $('#fname').val(); | |
var subject = $('#subject').val(); | |
var email = $('#email').val(); | |
var msg = $('#msg').val(); | |
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; | |
if (!regex.test(email)) { | |
alert('Please enter valid email'); | |
return false; | |
} | |
fname = $.trim(fname); | |
subject = $.trim(subject); | |
email = $.trim(email); | |
msg = $.trim(msg); | |
if (fname != '' && email != '' && msg != '') { | |
var values = "fname=" + fname + "&subject=" + subject + "&email=" + email + " &msg=" + msg; | |
$.ajax({ | |
type: "POST", | |
url: "mail.php", | |
data: values, | |
success: function() { | |
$('#fname').val(''); | |
$('#subject').val(''); | |
$('#email').val(''); | |
$('#msg').val(''); | |
$('.cf-msg').fadeIn().html('<div class="alert alert-success"><strong>Success!</strong> Email has been sent successfully.</div>'); | |
setTimeout(function() { | |
$('.cf-msg').fadeOut('slow'); | |
}, 4000); | |
} | |
}); | |
} else { | |
$('.cf-msg').fadeIn().html('<div class="alert alert-danger"><strong>Warning!</strong> Please fillup the informations correctly.</div>') | |
} | |
return false; | |
}); |
This file contains hidden or 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 | |
//Taking all values | |
$fname = $_POST['fname']; | |
$email = $_POST['email']; | |
$subject = $_POST['subject']; | |
$msg = $_POST['msg']; | |
$output = "Name: ".$fname."\n\nSubject: ".$subject."\n\nMessage: ".$msg; | |
$to = '[email protected]'; | |
$headers = 'FROM: "'.$email.'"'; | |
$send = mail($to, $fname, $output."\n\n***This message has been sent from me", $headers); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment