php jquery email send

Hi I have a following code, validation part and jquery works perfectly in the code but it dosent send the email

I have jquery.js file in the head section of html and it work perfectly

[code]


We will get back to you soon

<form id="contactform">
    <div>
        <label for="name">NAME:</label>
        <input type="text" name="name" id="name" placeholder="John Doe" />
   </div>
   <div>
       <label for="email">EMAIL:</label>
       <input type="text" name="email" id="email" placeholder="[email protected]" />
   </div>
   <div>
        <label for="comment">MESSAGE:</label>
        <textarea name="comment" rows="10" cols="50" id="comment"></textarea>
   </div>
   <input type="submit" name="submit" value="SEND" id="submit" />
</form>
[/code] ********************************************************************************

this page does the validation part from php
test.php
[php]

<?php if(isset($_POST["submit"])) { $errors = array(); $name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; $to = "[email protected]"; $from = $_POST['email']; $headers = "From: $from"; $flag = false; $success = mail($to,$comment,$headers); $emailReg = '/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ '; if(!($name) || !($email) || !($comment)){ if(!$name){ $errors[]="Missing Name"; } if(!$email){ $errors[]="Missing Email"; } if(!$comment){ $errors[]="Missing Comment"; } $json_response = json_encode($errors); }elseif(!preg_match($emailReg,$email)){ $errors[] = "Not a valid email address"; $json_response = json_encode($errors); }elseif($success){ $flag = true; return $flag;}else{ $json_response = json_encode("Thanks for your comment"); } echo $json_response; } ?>[/php]

this file does the jquery validation without page refresh
function.js

[code]
$(function(){
$("#emailsend").hide();
$("#submit").click(function(event) {
event.preventDefault();
var emailReg = /^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$/;
var errors = false;
var name = $(’[name=name]’).val();
var email = $(’[name=email]’).val();
var comment = $(’[name=comment]’).val();
$(’.errors’).remove();

    if($("#name").val() == ""){
        $("#name").after("<span class= 'errors'> Missing Name </span>");
        errors = true;
        }
    if($("#email").val() == ""){
        $("#email").after("<span class= 'errors'> Missing Email </span>");
        errors = true;
        }else if(!emailReg.test($('#email').val())){
            $("#email").after("<span class= 'errors'> Not valid Email </span>");
            errors = true;
            }
    if($("#comment").val() == ""){
        $("#comment").after("<span class= 'errors'> Missing Comment </span>");
        errors = true;
        }

if(errors == true) {
return false;
} else {
input_data = {
“name” : name,
“email” : email,
“comment”: comment,
“submit” : true
}
$.ajax({
type: ‘post’,
url: ‘test.php’,
data: input_data,
dataType: ‘json’,
success: function( msg ) {
$("#ack").html(msg);
$("#contactform").delay(500).slideUp(500);
$("#emailsend").show(700);
},
error: function() {
$("#ack").html(‘ERROR!’);
}
});
}
});
});[/code]

you’re missing the subject in there.

Sponsor our Newsletter | Privacy Policy | Terms of Service