tags:

views:

73

answers:

1

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!

+1  A: 

Recommendations

  1. Get firebug or httpfox to debug ajax scripts. You can see all requests made and the post/get variables.

  2. Dont use eregi use preg

  3. Dont use preg to validate email use php's filter functions

  4. Another debugging idea: set the $_POST vars above the email.php code and visit the email.php in your browser to see if its working.

Galen
Thanks, this helped a lot! Found out it was searching the wrong directory for the php file... Good old firebug.
Robert