Trouble with jquery email form submitHandler

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-05-15T01:56:23Z Indexed on 2010/05/15 2:04 UTC
Read the original article Hit count: 396

Filed under:
|
|

Here is the code I'm using for the submitHandler:

submitHandler: function() {
 $('.holder').fadeOut('slow');
 $('#loading').fadeIn('slow');
 $.post('email.php',{name:$('#em_name').val(), email:$('#em_email').val(), message:$('#em_message').val()},
 function(data){
  $('#loading').css({display:'none'}); 
  if( data == 'success') {
   $('#callback').show().append('Message delivered successfully');
   $('#emailform').slideUp('slow');
  } else {
   $('#callback').show().append('Sorry but your message could not be sent, try again later');
  }
 });  
}

This isn't working when used in conjunction with this php:

    <?php $name = stripcslashes($_POST['name']);
 $emailAddr = stripcslashes($_POST['email']);
 $message = stripcslashes($_POST['message']);
 $email = "Message: $message \r \n From: $name \r \n Reply to: $emailAddr";
 $to = '[email protected]';
 $subject = 'Message from example';

 //validate the email address on the server side
 if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailAddr) ) {
  //if successful lets send the message
  mail($to, $subject, $email);
  echo('success'); //return success callback
 } else {
  echo('An invalid email address was entered'); //email was not valid
 }
?>

Does anyone have any suggestions as to why this isn't working like it should. It seems to just lock up when I submit. Any help would be appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about email