我的HTML表单有什么问题?

时间:2017-09-08 17:25:33

标签: php html forms

我正在尝试获取一个简单的HTML表单,以便在有人提交回复时向我发送电子邮件。我对PHP不太熟悉,但我在网上找到了一些例子,并试图自己实现它。到目前为止,当点击提交按钮时,我被重定向到“quote.php”页面,它只显示一个空白的白色屏幕,我没有收到电子邮件。我真的很感激任何洞察我做错了什么!

form.html

<form class="from-contact" action="quote.php" method="post">
                        <input name="name" type="text" class="form-control" placeholder="Name">
                        <input name="email" type="email" class="form-control" placeholder="Email">
                        <textarea name="message" class="form-control textarea" placeholder="Description"></textarea>
                        <button type="submit" class="btn btn-default button submit">
                            submit now<i class="fa fa-angle-double-right"></i>
                        </button>
                    </form>

quote.php

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'Demo Contact Form'; 
        $to = 'jeremycollins@neawebservices.com'; 
        $subject = 'Message from Contact Demo ';

        $body = "From: $name\n E-Mail: $email\n Message:\n $message";

        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Please enter a valid email address';
        }

        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
    }
?>

0 个答案:

没有答案