联系表格不发送电子邮件,没有通知[重复]

时间:2022-10-25 21:35:53

This question already has an answer here:

这个问题在这里已有答案:

working on contact form for my website. All tree form fields are validating correctly somehow the email is not send but looks page is loading again. Can anyone check my code and tell me where could be a problem here. Would like temail to be sent and notification to the user shown.

在我的网站的联系表格上工作。所有树形式字段都以某种方式正确验证电子邮件未发送但看起来页面正在再次加载。任何人都可以检查我的代码并告诉我这里可能存在问题。希望发送temail并向用户显示通知。

Contact form:

<form role="form" id="contactForm">
     <div class="row">
            <div class="form-group">
                 <input type="text" class="form-control" name="name" id="name" placeholder="Wpisz swoje imię, nazwisko" required="required">
            </div>
            <div class="form-group">
                <input type="email" class="form-control" name="email" id="email" placeholder="Enter email" required>
            </div>

        <div class="form-group">
            <textarea id="message" name="message" class="form-control" rows="5" placeholder="Enter your message" required></textarea>
        </div>
        <button type="submit" id="form-submit" class="btn-block">Wyślij wiadomość</button>
<div id="msgSubmit" class="h3 text-center hidden">Message Submitted!</div>
     </div>
    </form>

Java sripts within same html file as form:

Java sripts在与表单相同的html文件中:

   <script>
$(document).ready(function () {

    var owl = $("#owl-hero");

    owl.owlCarousel({

        navigation: false, // Show next and prev buttons
        slideSpeed: 1,
        paginationSpeed: 400,
        singleItem: true,
        transitionStyle: "fade"

    })});


    </script>



    <script>
$("#contactForm").validator().on("submit", function (event) {
    if (event.isDefaultPrevented()) {
        // handle the invalid form...
    } else {
        // everything looks good!
        event.preventDefault();
        submitForm();
    }
});

function submitForm(){
    // Initiate Variables With Form Content
    var name = $("#name").val();
    var email = $("#email").val();
    var message = $("#message").val();

    $.ajax({
        type: "POST",
        url: "php/form-process.php",
        data: "name=" + name + "&email=" + email + "&message=" + message,
        success : function(text){
            if (text == "success"){
                formSuccess();
            }
        }
    })};
}
function formSuccess(){
    $( "#msgSubmit" ).removeClass( "hidden" );
}


</script>

PHP file (process.php) :

PHP文件(process.php):

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$EmailTo = "roger@gth.com.pl";
$Subject = "New Message Received";

// send email
$success = mail($EmailTo, $Subject, $message, $email);

// redirect to success page
if ($success){
   echo "success";
}else{
    echo "invalid";
}

?>

for further dicussion:

进一步说明:

my top code:

我的*代码:

<!DOCTYPE html>
        <html lang="pl">

        <head>

            <meta http-equiv="content-type" content="text/html; charset=UTF-8">

            <title>my site</title>
            <link rel="shortcut icon" href="img/ico.png">

            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="description" content="jakiś wyraz">
            <meta name="keywords" content="">
            <meta name="author" content="strona">

            <!-- Bootstrap Css -->
            <link href="bootstrap-assets/css/bootstrap.min.css" rel="stylesheet">
            <!-- Style -->
            <link href="plugins/owl-carousel/owl.carousel.css" rel="stylesheet">
            <link href="plugins/owl-carousel/owl.theme.css" rel="stylesheet">
            <link href="plugins/owl-carousel/owl.transitions.css" rel="stylesheet">
            <link href="plugins/Lightbox/dist/css/lightbox.css" rel="stylesheet">
            <link href="plugins/Icons/et-line-font/style.css" rel="stylesheet">
            <link href="plugins/animate.css/animate.css" rel="stylesheet">
            <link href="css/main.css" rel="stylesheet">
            <!-- Icons Font -->
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>



     <script>
    $(document).ready(function () {

        var owl = $("#owl-hero");

        owl.owlCarousel({

            navigation: false, // Show next and prev buttons
            slideSpeed: 1,
            paginationSpeed: 400,
            singleItem: true,
            transitionStyle: "fade"

        })});


        </script>



        <script>
    $("#contactForm").validator().on("submit", function (event) {
        if (event.isDefaultPrevented()) {
            // handle the invalid form...
        } else {
            // everything looks good!
            event.preventDefault();
            submitForm();
        }
    });

    function submitForm(){
        // Initiate Variables With Form Content
        var name = $("#name").val();
        var email = $("#email").val();
        var message = $("#message").val();

        $.ajax({
            type: "POST",
            url: "php/form-process.php",
            data: "name=" + name + "&email=" + email + "&message=" + message,
            success : function(text){
                if (text == "success"){
                    formSuccess();
                }
            }
        });
}
    function formSuccess(){
        $( "#msgSubmit" ).removeClass( "hidden" );
    }


    </script>    
        </head>

i notice couple errors in console please help me also to fix it.:

我注意到控制台中的几个错误请帮我修复它:

error type: SCRIPT5009: '$' is undefined

错误类型:SCRIPT5009:'$'未定义

on this line:

在这条线上:

$("#contactForm").validator().on("submit", function (event) {

error type: SCRIPT5009: '$' is undefined at the end on own.carousel script here:

错误类型:SCRIPT5009:在此处的own.carousel脚本末尾未定义'$':

});

1 个解决方案

#1


0  

You haven't loaded the jQuery library (or at least prior to attempting to use it based on your <head> tag from above), add:

你还没有加载jQuery库(或者至少在尝试使用它基于你上面的标签之前),添加:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>

before useing the $ function.

在使用$函数之前。

After jQuery has resolved, remove the syntax error cased by the extra } in your submitForm function -right in between the ) and the ;.

在jQuery解决之后,删除你的submitForm函数中的extra}所带来的语法错误。

#1


0  

You haven't loaded the jQuery library (or at least prior to attempting to use it based on your <head> tag from above), add:

你还没有加载jQuery库(或者至少在尝试使用它基于你上面的标签之前),添加:

<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>

before useing the $ function.

在使用$函数之前。

After jQuery has resolved, remove the syntax error cased by the extra } in your submitForm function -right in between the ) and the ;.

在jQuery解决之后,删除你的submitForm函数中的extra}所带来的语法错误。