HTML PHP联系表单-提交和消息问题


HTML PHP Contact Form - Submit and Message Issues

希望您能提供帮助,我正在尝试为我的网站创建一个联系人表单,该表单是HTML,使用CSS样式,并使用PHP发送电子邮件。

网站:Evan Ciniello

问题一:当通过联系人表单提交消息时,它不会重定向或刷新(最终位于www.evanciniello.ca/php/submit.php)

问题二:邮件正文在我的收件箱中不可见(即,我可以看到是谁发送了电子邮件,但无法阅读邮件)。

联系HTML表单

<div id="container" class="clearfix">
    <div class="element  clearfix col2-3 contact">
            <form id="contact-us" action="/php/submit.php" method="post">
                <h1>Contact Us!</h1>
              <input type="text" name="first_name" placeholder="NAME" required>
              <input  type="email" name="email" placeholder="MAIL" required>
              <textarea name="message" placeholder="MESSAGE" required ></textarea>
              <input id="button" type="submit" class="submit"></button>
            </form>
             <div id="error" style="display:none;"> Please Provide Valid Information</div>
            </div>
        </div>

PHP表单

<?php
if(isset($_POST['submit'])) { 
$to =  "contact@evanciniello.ca";
$subject = "Form Tutorial";
$name_field = $_POST['name'];                
$email_field = $_POST['email'];                             
$message = $_POST['message'];
$body = "From: $name_field'n E-Mail: $email_field'n Message:'n $message"; 
$success = mail($to, $subject, $body);
}
?>

这是正常的。在您的/php/submit.php

if (isset($_POST['submit'])) {
    if (empty($_POST["message"]) || empty($_POST["first_name"]) || empty($_POST["email"])) {
        //Set up some error messages here and show that to the users.
    } else {
        $to = "contact@evanciniello.ca";
        $subject = "Form Tutorial";
        $name_field = $_POST['first_name'];
        $email_field = $_POST['email'];
        $message = $_POST['message'];
        $body = "From: $name_field'n E-Mail: $email_field'n Message:'n $message";
        $success = mail($to, $subject, $body);
        if ($succes) {
            //Now we need to redirect
            $url = "http://www.evanciniello.ca/WHEREYOUWANTTOREDIRECT";
            Header("Location: " . $url);
        } else {
            //Set up error message, that message can not be setn
            die("Message can not be sent");
        }
    }
}

在提交中添加name

<input id="button" type="submit" class="submit" name="submit"></button>