一页网站联系表单问题

i have a one page portfolio with a contact form, i have been trying to troubleshoot this thing but have not succeeded. I am no PHP expert so I will try to explain as best as I can. Basically what I have is a contact template file from word press that i have used in the past, but what i want to do is (if possible) implement in my portfolio. My main issue is that when I preview my site in the browser it shows the PHP code that is on the form.

<?php
            if ($_SERVER['REQUEST_METHOD'] == "POST") {
                // Check fields for errors

                if (empty($_POST["txtName"])) {
                    $errors["txtName"] = "Please enter your name.";
                }

                if (empty($_POST["txtPhone"])) {
                    $errors["txtPhone"] = "Please enter your phone number.";
                }


                if (empty($_POST["txtEmail"])) {
                    $errors["txtEmail"] = "Please enter your email address.";
                } else {
                    if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST["txtEmail"])))) {
                        $errors["txtEmail"] = "Please provide a valid email address.";
                    }

                }

                if (count($errors) < 1) {

                        $to = "test-email@gmail.com";
                        $subject = 'Bave Designs Contact';
                        $headers = "From:" . $_POST["txtEmail"] . "
";
                        $headers .= "MIME-Version: 1.0
";
                        $headers .= "Content-Type: text/html; charset=UTF-8
";
                        $message = '<html><body style="font-family:Arial, Helvetica, sans-serif; font-size:12px;">';
                        $message .= '<p><strong>Name:</strong> ' . $_POST["txtName"] . '<br />

                                    <strong>Phone:</strong> ' . $_POST["txtPhone"] . '<br />
                                    <strong>Email:</strong> ' . $_POST["txtEmail"] . '<br />

                                    <strong>Message:</strong><br />' . $_POST["txtComment"] . '</p>
                                    </body>
                                    </html>';
                        if ( !mail($to,$subject,$message,$headers) ) {

                            $errors["send"] = "There was a problem sending your message.  Please try again.";
                        }

                } 
            }
            <div id="contact-form">
                    <?php
                if (count($errors) > 0) {
                    echo '<ul style="color:red; padding:0 0 18px 22px;">';
                    foreach ($errors as $error) {
                        echo "<li>" . $error . "</li>";
                    }
                    echo "</ul>";
                }
                ?>
                <?php if ($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) < 1) { ?>
            <p class="success-message"><?php _e('Thank you! Your message has been sent.'); ?></p>
            <?php } else { ?>

            <form id="contact1" method="post" action="#message" class="contact-form">
                <p><label for="txtName">Name</label>
                <input type="text" id="txtName" name="txtName" class="field" size="40" value="<?php echo $_POST['txtName'] ?>" /></p>

                <p><label for="txtPhone">Phone</label>
                <input type="text" id="txtPhone" name="txtPhone" class="field" size="40" value="<?php echo $_POST['txtPhone'] ?>" /></p>

                <p><label for="txtEmail">Email</label>
                <input type="text" id="txtEmail" name="txtEmail" class="field" size="40" value="<?php echo $_POST['txtEmail'] ?>" /></p>

                <p><label for="txtComment">Message</label>
                <textarea name="txtComment" id="txtComment" class="field" cols="40" rows="10"><?php echo $_POST['txtComment'] ?></textarea></p>

                <p><input type="submit" id="btnSubmit" name="btnSubmit" class="button" value="Submit" /></p>

            </form>
            <?php } ?>
        </div><!-- CONTACT FORM ENDS-->

I switched the wp_mail function to mail which I know is correct.

Any help would be appreciated.

Thanks in advance.

My main issue is that when I preview my site in the browser it shows the PHP code that is on the form.

So, if I understand correctly, your PHP codes are being shown in your page?

If that is the case, I urge you to contact your webhosting provider asap, because there seems to be a big problem with your Apache configuration.