I'm trying to Frankenstein a form using Tectite's FormMail and some jQuery/AJAX validation that displays a success message on the same page without page redirect.

The validation side is from a plugin. Instead of using their PHP mail script, though, I'm using Tectite's.

When I use Tectite, I receive the results of the form in my inbox, but the form itself displays an error message on submit. I know that I have to make the jQuery recognize that the PHP form has submitted, in order to display the success message. I don't know how to do this. I'm hoping someone can guide me in the right direction. I've tried a lot of things, I've read and searched, but you know it's time to post in the forums when you're typing in random bits of PHP hoping that something just "works." So please forgive me for my ignorance.

I'll post relevant code snippets - please let me know if any additional/full snippets would be helpful.

header:

Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type='text/javascript' src="js/validation.js"></script>
HTML:

Code:
<div id='container'>
  <form name="contactForm" id='contact_form' method="post" action='formmail.php'>
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">
    <input type="hidden" name="subject" value="" />
    <input type="hidden" name="derive_fields" value="email = senderEmail, realname = senderName, subject = ID + suggtitle" />
    <input type="hidden" name="mail_options" value="PlainTemplate=contact.txt,AlwaysList" />

<p> Your Name:
    <div id='name_error' class='error'><img src='images/error.png'>Please enter your name.</div>
    <div>
      <input type='text' name='name' id='name'>
    </div>
    </p>

<!-- [Other fields...] -->

<div id='mail_success' class='success'><img src='images/success.png'>Your message has been sent successfully.</div>
    <div id='mail_fail' class='error'><img src='images/error.png'> Sorry, error occured this time sending your message.</div>
    <p id='submit'>
      <input type='submit' id='send_message' value='Submit Form'>
    </p>

  </form>
validation.js:

Code:
$(document).ready(function(){
        $('#send_message').click(function(e){
            
            //Stop form submission & check the validation
            e.preventDefault();
            
            // Variable declaration
            [...]
            
            // Form field validation
            [...]

            // If there is no validation error, next to process the mail function
            if(error == false){
               // Disable submit button just after the form processed 1st time successfully.
                $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
                
				/* Post Ajax function of jQuery to get all the data from the submission of the form as soon as the form sends the values to email.php*/
                $.post("formmail.php", $("#contact_form").serialize(),function(result){
                    //Check the result set from email.php file.
                    if(result == 'sent'){
                        //If the email is sent successfully, remove the submit button
                         $('#submit').remove();
                        //Display the success message
                        $('#mail_success').fadeIn(500);
                    }else{
                        //Display the error message
                        $('#mail_fail').fadeIn(500);
                        // Enable the submit button again
                        $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                    }
                });
            }
        });    
    });
This is the original (from the plugin) email.php, but I've replaced it with Tectite's FormMail PHP.

email.php:

PHP Code:
<?php
$subject 
$_REQUEST['subject'] . ' Ajax HTML Contact Form : Demo'// Subject of your email
$to $_REQUEST['email'];  //Recipient's E-mail

$headers  'MIME-Version: 1.0' "\r\n";
$headers .= "From: " $_REQUEST['email'] . "\r\n"// Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

$message .= 'Name: ' $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['message'];

if (@
mail($to$subject$message$headers))
{
    
// Transfer the value 'sent' to ajax function for showing success message.
    
echo 'sent';
}
else
{
    
// Transfer the value 'failed' to ajax function for showing error message.
    
echo 'failed';
}
?>
Based on email.php, it seems like I should have something similar to echo 'sent' or 'failed' inside formmail.php.

Something like... ?

PHP Code:
if(isset($_POST['submitted']))
{
    
// Transfer the value 'sent' to ajax function for showing success message.
    
echo 'sent';
}
else
{
    
// Transfer the value 'failed' to ajax function for showing error message.
    
echo 'failed';
}
?> 
That doesn't work. I think I'm on the right track but I'm obviously doing something wrong. Any help would be GREATLY appreciated.