PHP contact form returning the PHP code when I press the submit button


I created a contact form for my website. When I click the submit button, it just shows the PHP code instead of the message it is supposed to show, like the text information the user inputs into the form.

Here is the HTML code for the form:

    <link href="contact.css" rel="stylesheet" type="text/css" />
        <title>Contact Us</title>

        <form action="contact.php" method="post">
            <div id="ContactForm">
                    <h4>Contact Parquest:</h4>

                    <label class="labelone" for="name">Name:</label>
                    <input name="name"/>

                    <label for="email">Email: </label>
                    <input name="email"email"/>

                    <label for="commens">Comments: </label>
                    <textarea name="commens"></textarea>
                    <input class="btn" type="submit" value="Send Email"/>
                    <input class="btn" type="reset" value="Reset Form"/>

I couldn't post the PHP code, because it just doesn't show when I try, so here's a screenshot:

Enter image description here

Best Solution

There is no problem to your code.. The problem is on your environment.. I guess you are not running the html file through a server..

If the url on your browser looks like these:


then you are doing it wrong.. in order to run .php scripts, you need a web server like apache or nginx... the url of should be like these


then the php file should run as expected..

php files are interpreted scripting language and thus it needs an interpreter in the server in order to run.. if it is just browsed in the browser without a server, it will just output the code inside..

Related Question