Jquery submitHandler email issue

Here is the code I use for 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 does not work 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 = 'mail@example.com';
 $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 is not working as it should. I seem to just lock myself when I obey. Any help would be greatly appreciated. Thank!

+3
source share
1 answer

Recommendations

  • Get firebug or httpfox for debugging ajax scripts. You can see all the requests made and the post / get variables.

  • Do not use eregi use preg

  • Do not use preg to check email usage of php filter function

  • : $_POST email.php email.php , , .

+1

Source: https://habr.com/ru/post/1745529/


All Articles