从联系表收到的邮件中缺少信息

时间:2019-03-16 00:41:40

标签: php html forms web contacts

我的联系表有效,但不显示发件人的姓名和电子邮件,仅显示邮件。它只是一个简单的html,css和php文件。谁能看看我是否想念些东西。

这是html的一部分,联系表区域要具体:

<section id="gtco-contact" data-section="contact">
    <div class="container">
        <div class="row row-pb-md">
            <div class="col-md-8 col-md-offset-2 heading animate-box" data-animate-effect="fadeIn">
                <h1>Contact Us</h1>
                <p class="sub">you might need</p>
                <p class="subtle-text animate-box" data-animate-effect="fadeIn">Contact</p>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6 col-md-push-6 animate-box">
                <form method="post" action="form-process.php">
                    <div class="form-group">
                        <label for="name" class="sr-only">Name</label>
                        <input type="text" class="form-control" placeholder="Name" id="name">
                    </div>
                    <div class="form-group">
                        <label for="email" class="sr-only">Email</label>
                        <input type="text" class="form-control" placeholder="Email" id="email">
                    </div>
                    <div class="form-group">
                        <label for="message" class="sr-only">Message</label>
                        <textarea name="message" id="message" class="form-control" cols="30" rows="7" placeholder="Message"></textarea>
                    </div>
                    <div class="form-group">
                        <input type="submit" value="Send Message" class="btn btn-primary">
                    </div>
                </form>
            </div>
            <div class="col-md-4 col-md-pull-6 animate-box">
                <div class="gtco-contact-info">
                    <ul>
                        <li class="phone"><a href="tel://0092">+ 98 00000000</a></li>
                        <li class="email"><a href="mailto:info@yoursite.com">info@hex.com</a></li>
                        <li class="url"><a href="#">http://ex.com</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</section>

这是我使用的php代码,它只是一个简单的php代码:

  <?php

     $errorMSG = "";

     // NAME
         if (empty($_POST["name"])) {
         $errorMSG = "Name is required ";
         } else {
         $name = $_POST["name"];
         }

    // EMAIL
    if (empty($_POST["email"])) {
        $errorMSG .= "Email is required ";
         } else {
            $email = $_POST["email"];
          }

    // MESSAGE
        if (empty($_POST["message"])) {
        $errorMSG .= "Message is required ";
        } else {
        $message = $_POST["message"];
         }


                $EmailTo = "info@ex.com";
                $Subject = "New Message From HE";

        // prepare email body text
           $Body = "";
           $Body .= "Name: ";
           $Body .= $name;
           $Body .= "\n";
           $Body .= "Email: ";
           $Body .= $email;
           $Body .= "\n";
           $Body .= "Message: ";
           $Body .= $message;
           $Body .= "\n";

     // send email
          $success = mail($EmailTo, $Subject, $Body, "From:".$email);

    // redirect to success page
          if ($success && $errorMSG == ""){
            echo "success";
             }else{
          if($errorMSG == ""){
        echo "Something went wrong :(";
      } else {
         echo $errorMSG;
       }
      }

    //refer to index
        header("Location: index.html");
     ?>

0 个答案:

没有答案