I have a form which upon submission directs to a aspx page, which uses the form's data. Before directing to the above stated page, jquery is used alongside ajax to retrieve form values, and it sends everything to my php email file, which should be sending me informational emails whenever a form is submitted. Unfortunately I recevie nothing, everything else works, but I don't receive any email. Please help, I'm not sure why this isn't working.
Additional Info: I'm using wordpress and have called the jquery file via the functions.php. The php file is called via the jquery file.
Thanks in Advance!
HTML Form
<form action="https://redirection_page.aspx" method="get" name="nform" id="nform">
<div class="submission">
<div class="fname">
<input type="text" name="firstName" class="fname" placeholder="First name" required="">
</div>
<br>
<div class="lname">
<input type="text" name="lastName" class="lname" placeholder="Last name" required="">
</div>
<br>
<div class="email">
<input type="email" name="email" class="email" placeholder="example@email.com" required="">
</div>
<br>
<div class="phone">
<input type="text" name="homePhone" class="phone" placeholder="Phone Number" required="">
</div>
<br>
<br>
<!-- Edit the Continue Text -->
<div class="form-button">
<input type='button' class="submit tp-button green big :hover.green" value="Continue">
</div>
</div>
</form>
Jquery/Ajax
jQuery(document).ready(function($) {
var nform = $('#nform');
$('#nform .form-button input.submit').click(function(){
var data = {
first : $("#nform input.fname").val(),
last : $("#nform input.lname").val(),
email : $("#nform input.email").val(),
phone : $("#nform input.phone").val(),
};
$.ajax({
type: "POST",
url: "/wp-content/themes/Avada/email.php",
data: data,
success: function(){
$('#nform').submit();
}
});
});
});
PHP Mail
<?php
if($_POST){
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$sendto = "myemailaddress@gmail.com";
$message = "";
$message .= "<p> Name: " . $first . " " . $last "</p>";
$message .= "<p> Email: " . $email . "</p>";
$message .= "<p> Phone Number: " . $phone . "</p>";
$mail = 'no-reply@'.str_replace('www.', '', $_SERVER['SERVER_NAME']);
$uniqid = md5(uniqid(time()));
$headers = 'From: '.$mail."\r\n";
$headers .= 'Reply-to: '.$mail."\r\n";
$headers .= 'Return-Path: '.$mail."\r\n";
$headers .= 'Message-ID: <'.$uniqid.'@'.$_SERVER['SERVER_NAME'].">\r\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\r\n";
$headers .= 'X-Priority: 3'."\r\n";
$headers .= 'X-MSMail-Priority: Normal'."\r\n";
$headers .= 'Content-Type: multipart/mixed;boundary="----------'.$uniqid.'"'."\r\n";
$headers .= '------------'.$uniqid."\r\n";
$headers .= 'Content-transfer-encoding: 7bit';
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//send email
mail($sendto, "Apply Submission by " .$email, $message, $headers);
}
?>