I'm looking to submit a single form input for a tracking number using jquery/php so that the page doesn't refresh. I am able to submit the form and have the email sent to me but can't figure out what to put in $email_body so it actually emails me the form info. The email will send blank (So I assume email is in the PHP code). Please see below for HTML/JS/PHP:
HTML:
<form id="track-form" accept-charset="UTF-8" action="" size="30" class="form-inline" method="POST">
<input class="focus" name="tracking" id="tracking" placeholder="tracking code" value="" type="text"/>
<input class="btn btn-default btn-track" name="submit" type="submit" value="Send" />
<img id="success" style="display:none" src="img/check.png" />
<br>
<label class="error" for="tracking" id="track-error">You must enter your tracking code!</label>
</form>
JS:
$(document).ready(function() {
$('.error').hide();
$("#track-form").on('submit', function(e) {
$('.error').hide();
var track = $("input#tracking").val();
if (track == "") {
$("label#track-error").show();
$("input#tracking").focus();
return false;
};
$.ajax({
url:'sendtrack.php',
data:$(this).serialize(),
type:'POST',
success:function(data){
console.log(data);
$("#success").fadeIn(300); //=== Show Success Message==
},
});
e.preventDefault();
});
});
PHP (WHERE THE PROBLEM IS):
<?php
$track = $_POST['tracking'];
$email_from = 'info@website.com';
$email_subject = "New Tracking Info";
$email_body = "Tracking Number: $track".
$to = "email@gmail.com";
$headers = "From: $email_from
";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
?>
If I leave $email_body as is I get a "500 Server Error". If I leave it blank I get an email with just "email@gmail.com" in it, no tracking number.
Thanks in advance for your help!