【问题标题】:Trouble with jquery email form submitHandlerjquery电子邮件表单submitHandler的问题
【发布时间】:2011-02-19 18:48:34
【问题描述】:

这是我用于 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');
  }
 });  
}

与这个 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
 }
?>

有没有人对为什么这不能正常工作有任何建议。当我提交时,它似乎只是锁定了。任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: php jquery email


    【解决方案1】:

    建议

    1. 获取 firebug 或 httpfox 来调试 ajax 脚本。您可以查看发出的所有请求以及发布/获取变量。

    2. 不要使用eregi 使用preg

    3. 不要使用 preg 验证电子邮件使用 php's filter functions

    4. 另一个调试思路:在 email.php 代码上方设置 $_POST 变量,然后在浏览器中访问 email.php 以查看其是否工作。

    【讨论】:

    • 谢谢,这帮助很大!发现它正在为 php 文件搜索错误的目录...好老萤火虫。
    猜你喜欢
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    相关资源
    最近更新 更多