Last active
March 26, 2018 17:07
-
-
Save wmucheru/bd87543cd206cadc2e436ac91a811cc9 to your computer and use it in GitHub Desktop.
Send email with headers (Prevents going to spam)
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
<form class="form-horizontal col-md-10 cform" id="cform"> | |
<div class="form-group"> | |
<label class="control-label">Name*</label> | |
<input type="text" class="form-control" name="name" required /> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">E-mail Address*</label> | |
<input type="email" class="form-control" name="email" required/> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">Subject*</label> | |
<input type="text" class="form-control" name="subject" required/> | |
</div> | |
<div class="form-group"> | |
<label class="control-label">Message*</label> | |
<textarea col="10" rows="5" class="form-control" name="message" required></textarea> | |
</div> | |
<div class="form-group"> | |
<button type="submit" class="btn btn-success">Send Message</button> | |
</div> | |
</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
<script> | |
$(document).ready(function(){ | |
var form = $('#cform'); | |
form.submit(function(e){ | |
e.preventDefault(); | |
$.ajax({ | |
type: 'POST', | |
url: '/send.php', | |
data: form.serialize(), | |
success: function(response){ | |
alert('Email sent'); | |
console.log(response); | |
}, | |
error: function(a,b,c){ | |
alert('Could not send email'); | |
console.log(a,b,c) | |
} | |
}); | |
}); | |
}); | |
</script> |
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']; | |
$subject = $_POST['subject']; | |
$message = $_POST['message']; | |
if($name == '' || $email == ''){ | |
echo 'Name and email are required'; | |
} | |
else{ | |
$headers = "From: ShineExtreme <info@shineextreme.co.ke>\n"; | |
// $headers .= "Cc: Victor <wvictormbuguah@yahoo.com>\n"; | |
$headers .= "Cc: William <willyk99@gmail.com >\n"; | |
$headers .= "X-Sender: $name <$email>\n"; | |
$headers .= 'X-Mailer: PHP/' . phpversion(); | |
$headers .= "X-Priority: 1\n"; | |
$headers .= "Return-Path: info@shineextreme.co.ke\n"; | |
$headers .= "MIME-Version: 1.0\r\n"; | |
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; | |
mail($to, $subject, $message, $headers); | |
echo 'Email sent...'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment