消息在PHP中传递确认

i am making a php website for my semester project ...and i have a contact us page in which user send me a message and the message is stored in database . but i want that when user type the message and click the send button then after checking form validation it send the user that "your message is delivered." and if there is something wrong in the validation then it tells user to type acc to requirements, here is my code.

    <?php
    // define variables and set to empty values
   $yournameErr = $emailErr = $messageErr = "";
     $yourname = $email = $message = "";

     if ($_SERVER["REQUEST_METHOD"] == "POST")
      {

         if (empty($_POST["yourname"]))
           {$yournameErr = "Name is required"; }
         else
           {$yourname = test_input($_POST["yourname"]);}

         if (empty($_POST["email"]))
           {$emailErr = "Email is required";}
              else
                {$email = test_input($_POST["email"]);
                  // check if e-mail address syntax is valid
                  if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
                     {
             $emailErr = "Invalid email format"; 
            }
           }

           if (empty($_POST["message"]))
               {$messageErr = "Message is required"; }
             else
              {$message = test_input($_POST["message"]);}
                   }

                function test_input($data)
              {
             $data = trim($data);
                 $data = stripslashes($data);
               $data = htmlspecialchars($data);
             return $data;
                   }

and my form is :

                   <form action="contact.php" name="Form1" id="Form1" method="post">
                    <div>
                        <label>Your Name:</label>
                        <br />
                        <input type="text" name="yourname"          
     id="yourname" placeholder="Full Name" style="border:1;  border-color:#000000; " />
                        <span class="error">* <?php echo  
        $yournameErr;?></span>
                    </div>

                    <br />
                    <br />
                    <div>
                        <label> Email :</label> <br />
                        <input name="email" type="text" 
  id="email" size="20" placeholder="Email" style="border:1;  border-color:#000000; " />
                        <span class="error">* <?php echo 
    $emailErr;?></span>
                    </div>
                    <br />
                    <br />
                    <div>
                        <label> Subject : </label><br />
                        <input name="subject" type="text" 
        id="subject" size="20" placeholder="Subject" style="border:1;  border-
        color:#000000; "  />
                    </div>
                    <br />
                    <br />
                    <div>
                        <label> Message :<br /> </label>
                        <textarea rows="5" cols="40"  
         name="message" type="text" id="message" placeholder="The message you want to 
           send to us." style="border:1;  border-color:#000000 " >
                        </textarea>
                        <span class="error">* <?php echo 
         $messageErr;?></span>
                    </div> 
                    <br />
                    <br />
                    <div>
                        <input type="submit" name="button" 
          id="button" style="border:1; border-color:#999999; " value="SEND"/>
                    </div>


          </form>

Assuming that your HTML code is in the same file as your PHP code you can add this to your HTML code:

<?php if(isset($messageErr) && $messageErr){ ?>
<div class="error"><?php echo $messageErr; ?></div>
<?php } ?>
<?php if($_SERVER["REQUEST_METHOD"] == "POST" && !$messageErr){ ?>
<div class="error">Message Delivered</div>
<?php } ?>

Just make sure that the PHP code and HTML code is both in the one .php file and the form action value is also the same .php file.