doubao7287 2015-02-17 03:40
浏览 27
已采纳

基金会5反馈表中的多封电子邮件

I'm very much a beginner, but I've managed to put together a feedback form for my website. The problem I'm having is that the form is sending 2 emails rather than 1. Any thoughts on what is causing this?

$('#myForm') 
    .on('valid.fndtn.abide', function () {
    var name = $("input#name").val();
    var email = $("input#email").val();
    var message = $("textarea#message").val();

    var dataString = 'name=' + name +
          '&email=' + email +
          '&message=' + message;

    $.ajax({
      type: "POST",
      url: "/contact/mail.php",
      data: dataString,
      success: function() {
        $('.contactform').html("<div id='thanks'></div>");
          $('#thanks').html("<h2>Thanks!</h2>")
          .append("<p>Dear "+ name +"!, We will get back to you as soon as we can.</p>")
          .hide()
          .fadeIn(1500);
      },
    });  //ajax call
    return false;
 });

PHP:

<?php

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$msg = "

Name: $name
Email: $email
Comments:
$message
";

$to = "email@example.com";
$subject = "Website";
$message = $msg;
$headers = "Website";
mail($to,$subject,$message,$headers);

?>
  • 写回答

1条回答 默认 最新

  • dongqiang8683 2015-02-18 04:09
    关注

    Apparently Foundation 5 still contains an old call function from a prior release "valid" vs "valid.fndtn.abide" which is causing it to be called twice. I was able to prevent the double emails by making the following changes:

    $('#myForm') 
    .on('valid.fndtn.abide', function (e) {
      if(e.namespace != 'abide.fndtn') {
        return;
      }
      var name = $("input#name").val();
      var email = $("input#email").val();
      var message = $("textarea#message").val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题