This question already has answers here:
</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail" dir="ltr">PHP mail function doesn't complete sending of e-mail</a>
<span class="question-originals-answer-count">
(26 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2015-11-08 09:36:45Z" class="relativetime">4 years ago</span>.</div>
</div>
</aside>
I'm trying to send a simple email from a form via jquery/AJAX. Any idea why this isn't working?
HTML:
<input id="referral-name" name="referral-name" type="text" placeholder="Your Name (First, Last)">
<input id="referral-email" name="referral-email" type="email" placeholder="Your Email">
<input id="friend-email" name="friend-email" type="email" placeholder="Your Friend's Email">
<button id="submit-referral">Send Referral</button>
Javascript:
$("#submit-referral").click(function () {
var data = {
referral-email: $("#referral-email").val(),
referral-name: $("#referral-name").val(),
friend-email: $("#friend-email").val()
};
$.ajax({
type: "POST",
url: "referral-email.php",
data: data,
success: function () {
alert('Referral Sent');
}
});
});
PHP (named referral-email.php
at the root of my folder):
<?php
if($_POST){
$referral_name = $_POST['referral-name'];
$referral_email = $_POST['referral-email'];
$friend_email = $_POST['friend-email'];
//send email
mail("my_email@email.com", "Referral Submission by ".$referral_name, $referral_name." (".$referral_email.") sent ".$friend_email." a referral.");
}
?>
</div>