I have a form which uses event.preventdefault. I then use Ajax to start the script which works fine. I then use PHP to send an email which also works fine apart from I'm not getting any values from my form inserted into the email - any ideas to why? The email still sends but only with the hardcoded message.
Form:
<form action="post.php" class="enquire-form" method="post">
<label for="" class="darktext">Contact details</label>
<div class="form-group">
<input class="form-control" type="text" name="name" id="name" placeholder="NAME" min="2" maxlength="75" required>
</div>
<div class="form-group">
<input class="form-control" type="number" name="contact-number" id="contact-no" placeholder="PHONE NUMBER" min="6" maxlength="20" required>
</div>
<div class="form-group">
<input class="form-control" type="email" name="email" id="email" placeholder="EMAIL ADDRESS" maxlength="40" min="4" required>
</div>
<label for="" class="darktext">Job details</label>
<div class="form-group ">
<input class="form-control" type="text" name="job-title" id="job-title" value="" placeholder="TYPE OF JOB" maxlength="300" min="5" required>
</div>
<div class="form-group ">
<input class="form-control" type="text" name="job-location" id="job-location" value="" placeholder="JOB LOCATION" maxlength="75" required>
</div>
<div class="g-recaptcha" data-sitekey="REMOVED"></div>
<button type="submit" class="submit-job signbuttons btn btn-primary">
<span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>
Send enquiry
</button>
PHP
$name = $_POST['#name'];
$number = $_POST['#contact-no'];
$email = $_POST['#email'];
$jobTitle = $_POST['#job-title'];
$jobLocation = $_POST['#job-location'];
$message = "Job request: \n Name: $name \n Contact Number: $number \n Email:
$email \n Job Title: $jobTitle \n Job location: $jobLocation";
$to = 'me@example.com';
$subject = "Enquiry from $name";
$headers = 'From: me@ex.com' . "\r\n" .
'Reply-To: me@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Ajax:
$('.enquire-form').submit(function(e) {
e.preventDefault();
$this = $(this);
$.ajax({
type: "POST",
url: "post.php",
data: $this.serialize()
}).done(function(data) {
alert("Email sent, we'll be in touch soon.");
$(".submit-job").attr("disabled", true).prop('title', 'Your request has already been sent');
}).fail(function( jqXHR, textStatus ) {
alert("Failed to send the request: " + textStatus);
});
});
Thanks