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

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:

file:///c:/path/to/your/file/page.html

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

http://localhost/path/to/file/page.html

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..


I have executed the given code. It's working fine on my local server. Conventionally it should print the value inputs posted by form on contact.php.

But the thing I noticed in your PHP code is the variable name is $commets, instead of $comments.


You need a web server to run php scripts. Try installing wamp and then run your page under localhost.

Tags:

Html

Php

Forms