I am trying to send my form through ajax using jquery and send input values through phpMailer and it is not working. The emails are sending, but the values are blank. It was working before but I don't know what changed.
Here is my form:
<form role="form" id="submissionForm" enctype="multipart/form-data" name="submissionForm" method="post" >
<div class="form-group has-feedback" id="fnamediv">
<label class="control-label" for="fname">First Name:</label>
<input type="text" class="form-control" id="fname" required>
<span id="fnameglyph" class="glyphicon glyphicon-ok form-control-feedback hidden"></span>
</div>
<div class="form-group has-feedback" id="mnamediv">
<label class="control-label" for="mname">Middle Name:</label>
<input type="text" class="form-control" id="mname" placeholder="Optional" >
<span id="mnameglyph" class="glyphicon glyphicon-ok form-control-feedback hidden"></span>
</div>
<div class="form-group has-feedback" id="lnamediv">
<label class="control-label" for="lname">Last Name:</label>
<input type="text" class="form-control" id="lname" required>
<span id="lnameglyph" class="glyphicon glyphicon-ok form-control-feedback hidden"></span>
</div>
<div class="form-group has-feedback" id="emaildiv">
<label class="control-label" for="email">Email Address:</label>
<input type="email" class="form-control" id="email" required>
<span id="emailglyph" class="glyphicon glyphicon-ok form-control-feedback hidden"></span>
</div>
<hr><hr>
<br>
<div class="form-group has-feedback" id="submissionTitleDiv">
<label class="control-label" for="submissionTitle">Submission Title:</label>
<input type="text" class="form-control" id="submissionTitle" required>
<span id="subtitleglyph" class="glyphicon glyphicon-ok form-control-feedback hidden"></span>
</div>
<div class="form-group" id="subTypeDiv">
<label class="control-label" for="sel1">Submission Type:</label>
<select class="form-control" id="sel1" required>
<option style="display:none;" value="default" selected disabled>Select One</option>
<option value="Short Story">Short Story</option>
<option value="Poem">Poem</option>
<option value="Comic">Comic</option>
<option value="Art">Art</option>
</select>
</div>
<br>
<label for="file-upload" class="custom-file-upload" id="fileUploadBtn">
Upload File
</label>
<input id="file-upload" type="file" name="file-upload" accept=".pdf,.tiff,.tif,.jpg,.jpeg" required/>
<br><br><br>
<button type="submit" class="btn btn-danger" id="submitBtn" disabled>Submit</button>
<br>
</form>
Here is my jquery:
function submitForm(){
var fd = new FormData(document.querySelector("#submissionForm"));
$.ajax({
url: "php/process.php",
type: "POST",
data: fd,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success : function(text){
if (text == "success"){
formSuccess();
}
else{
formFailure();
}
}
}
);
}
And my php code:
require 'PHPMailerAutoload.php';
$name = $_POST["fname"];
$email = $_POST["email"];
$title = $_POST["title"];
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "*****";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "example@example.com";
$mail->Password = "password";
$mail->SetFrom("example@example.com");
$mail->Subject = "Poem | ".$title." | ".$fname;
$mail->Body = "Submission:<br><br>From: ".$email;
$mail->AddAddress("test@gmail.com");
$mail->AddAttachment($_FILES['file-upload']['name']);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "success";
}