jQuery AJAX form using mail() PHP script sends email, but POST data from HTML form is undefined

前端 未结 6 1627
青春惊慌失措
青春惊慌失措 2020-11-27 05:07

Thanks for taking the time to look, guys. I\'m creating a pretty basic AJAX contact form using jQuery. The email sends, but upon opening the email there is no POST data, so

6条回答
  •  星月不相逢
    2020-11-27 05:48

    Leave your email.php code the same, but replace this JavaScript code:

     var name = $("#form_name").val();
            var email = $("#form_email").val();
            var text = $("#msg_text").val();
            var dataString = 'name='+ name + '&email=' + email + '&text=' + text;
    
            $.ajax({
                type: "POST",
                url: "email.php",
                data: dataString,
                success: function(){
                $('.success').fadeIn(1000);
                }
            });
    

    with this:

        $.ajax({
            type: "POST",
            url: "email.php",
            data: $(form).serialize(),
            success: function(){
            $('.success').fadeIn(1000);
            }
        });
    

    So that your form input names match up.

提交回复
热议问题