I'm using $.post in my js to check my form and if all is okay, the data will go to my sendinquiry.php which will send the contact form email. All is working just that I can't catch the echo "submitted" to sdata so that I can display the thank you message in jQuery. Anyone?
jQuery
.
.
.
if(errflag > 0){
$('.disclaimer').addClass('errortext');
}
else {
$.post(
"sendinquiry.php",
$('#contact_form').serialize(),
function(sdata)
{
if(sdata == 'submitted') {
var ntext = '<div class="row topbot_m shortwidth"><div class="columns medium-12 text-center"><h3>THANK YOU FOR SUBMITTING YOUR ENQUIRY.</h3><p>Our Sales Representative will contact you shortly.</p></div></div>';
$('#contact_form').hide().html(ntext).fadeIn('slow');
}
}
);
}
PHP
<?php
$subject = "Line Enquiry Form";
$gname = "High Line";
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$contactno = $_POST['contactno'];
$emailadd = $_POST['emailadd'];
$fmessage = $_POST['message'];
require 'PHPMailermaster/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($emailadd, $fname);
$mail->addAddress('sender@gmail.com', 'Reza San'); // Add a recipient
$mail->addReplyTo($emailadd, $fname +' '+$lname);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body ="<html>
<head>
<title>".$gname."</title>
</head>
<body>
<h2>".$subject."</h2>
<table>
<tr><td width='200'>First Name: </td><td>".$fname."</td></tr>
<tr><td width='200'>Last Name: </td><td>".$lname."</td></tr>
<tr><td width='200'>Contact No: </td><td>".$contactno."</td></tr>
<tr><td width='200'>Email Address: </td><td>".$emailadd."</td></tr>
<tr><td width='200'>Message: </td><td>".$fmessage."</td></tr>
</table>
</body>
</html>";
if($mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'submitted';
}
?>