联系表格不发送textarea值

时间:2016-11-12 19:59:57

标签: javascript php html email textarea

所以,如果我有一个简单的联系表格,包括姓名,电子邮件,网站和消息字段。问题是消息字段的内容未显示在电子邮件中。

电子邮件如下所示:

Name: jake tester
Email: jake@gmail.com
Website: example.com
Message: undefined

这是我的代码:

<form id="contactForm" method="POST">
            <div class="row small-margin">
                <div class="col-md-4">
                    <i class="pe-7s-user pe-2x icon-contact"></i>
                    <input name="name" type="text" placeholder="Name(required)" required size="35">
                </div> 
                <div class="col-md-4">
                    <i class="pe-7s-mail pe-2x icon-contact"></i>
                    <input name="email" type="email" placeholder="Email(required)" required size="35">
                </div>
                <div class="col-md-4">
                    <i class="pe-7s-link pe-2x icon-contact"></i>
                    <input name="website" type="text" placeholder="Website" size="35">
                </div>
            </div>
            <div class="row small-margin">
                <div class="col-md-12">
                    <!-- Message Field -->
                    <textarea name="message" placeholder="Your Message(required)" required></textarea>
                    <!-- Submit Button -->
                    <button id="submit" name="submit" type="submit" class="button" value="submit">SEND MESSAGE</button>
                    <!-- Success Message -->
                    <div id="msgSubmit" class="alert alert-success text-center hidden">Message Sent Successfully</div>
                </div>
            </div>
 </form>

和JS:

$("#contactForm").submit(function(event){
    // cancels the form submission
    event.preventDefault();
    console.log( $( this ).serialize() );
    });


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

我的PHP:

<?php
    // Set variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $website = $_POST['website'];
    $message = $_POST['message'];

    $to = 'novakim92@gmail.com'; 
    $subject = 'New Message from Nixo';

    // Prepare email body text
    $Body .= "Name: ";
    $Body .= $name;
    $Body .= "\n";

    $Body .= "Email: ";
    $Body .= $email;
    $Body .= "\n";

    $Body .= "Website: ";
    $Body .= $website;
    $Body .= "\n";

    $Body .= "Message: ";
    $Body .= $message;
    $Body .= "\n";

    // Send email
    $success = mail($to, $subject, $Body, "From:".$email);

    if ($success){
       echo "success";
    }else{
        echo "<p>Something went wrong, please try again!</p>";
    }
?>

我一直在摸不着头脑,我不知道是什么导致了这一点。非常感谢任何帮助。

0 个答案:

没有答案