试图创建一个“联系我们”模式表单,我得到未定义的索引

时间:2015-09-12 11:56:06

标签: php jquery html email

所以,我对编码比较陌生,我一直在尝试使用bootstrap为朋友设计网站。这是表单的代码:

    <form class="form-horizontal" method="post" id="form">
                <div class="modal-header">
                    <h4>Contact us for support</h4>
                </div>
                <div class="modal-body">

                    <div class="form-group">

                        <label for="contact-email" class="col-lg-2 control-label">Email</label>
                        <div class="col-lg-10">
                            <input type="email" class="form-control" name="contact-email" placeholder="you@example.com">
                        </div>

                    </div>

                    <div class="form-group">

                        <label for="contact-subj" class="col-lg-2 control-label">Subject:</label>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" name="contact-subj" placeholder="The reason you are contacting us">
                        </div>

                    </div>

                    <div class="form-group">

                        <label for="contact-msg" class="col-lg-2 control-label">Message:</label>
                        <div class="col-lg-10">

                            <textarea name="contact-msg" class="form-control" placeholder="Your message goes here" rows="8" cols="30"></textarea>

                        </div>

                    </div>


                </div>
                <div class="modal-footer">
                    <a class="btn btn-default" data-dismiss="modal">Cancel</a>
                    <input type="submit" name="submit" class="btn btn-primary" value="Send"></input>
                </div>
            </form>

Javascript:

    <script language="JavaScript">
        $(document).ready(function() {
        $("#submit").click(function() {
        var subj = $("#contact-subj").val();
        var email = $("#contact-email").val();
        var message = $("#contact-message").val();
        $("#returnmessage").empty(); // To empty previous error/success message.
        // Checking for blank fields.
        if (name == '' || email == '' || message == '') {
        alert("Please Fill Required Fields");
        } else {
        // Returns successful data submission message when the entered information is stored in database.
        $.post("http://localhost/php/contact-form-handler.php", {
        email1: email,
        message1: message,
        subject1: subj
        }, function(data) {
        $("#returnmessage").append(data); // Append returned message to message paragraph.
        if (data == "Your Query has been received, We will contact you soon.") {
        $("#form")[0].reset(); // To reset form fields on success.
        }
        });
        }
        });
        });
    </script>

和php:

    <?php
$email = $_POST['email1'];
$message = $_POST['message1'];
$subject = $_POST['subj'];
$email = filter_var($email, FILTER_SANITIZE_EMAIL); // Sanitizing E-mail.

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {


$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:' . $email. "\r\n"; // Sender's Email
$template = '<div style="padding:50px; color:white;">Hello ' . $name . ',<br/>'
. '<br/>Thank you...! For Contacting Us.<br/><br/>'
. 'Name:' . $name . '<br/>'
. 'Email:' . $email . '<br/>'
. 'Contact No:' . $contact . '<br/>'
. 'Message:' . $message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We Will contact You as soon as possible .</div>';
$message = "<div style=\"background-color:#7E7E7E; color:white;\">" . $template . "</div>";

$message = wordwrap($message, 70);

mail("ssiannas@gmail.com", $subject, $message, $headers);
echo "Your Query has been received, We will contact you soon.";
}
else {
echo "<span>* invalid email *</span>";
}
?>

我使用xampp在本地托管了php文件,但仍然无法使用该电子邮件。我只是没有得到表单的响应,而如果我把action="http://localhost/php/contact-form-handler.php"我得到了不明的索引在php的第3,4,5行($ _POSTs)

0 个答案:

没有答案