You need to name your contact page with a .php extenstion, not a .html
the PHP code will not be visible to the browser at all. It will just send the mail, if a sendMail server is set up(it should be).
I'll expand it a bit for you.
file name: contact.php
PHP Code:
<form action="contact.php" method="post">
Name: <input type="text" name="name" />
<br />
E-Mail: <input type="text" name="email" />
<br />
Subject: <input type="text" name="subject" />
<br />
Message: <textarea name="message" rows="4" cols="25"></textarea>
<br />
<input type="submit" value="Send!" />
</form>
<?php
//First get the information that the user entered and create smaller named variables
if($_POST['name'] == NULL || $_POST['email'] == NULL || $_POST['subject'] == NULL || $_POST['message'] == NULL) echo 'You must fill in ALL fields before submitting your request!';
else {
$name = ($_POST['name'] != NULL) ? strip_tags($_POST['name']) : 'No Name';
$email = ($_POST['email'] != NULL) ? strip_tags($_POST['email']) : 'No Email Address';
$subject = ($_POST['subject'] != NULL) ? strip_tags($_POST['subject']) : 'Contact Form';
$message = ($_POST['message'] != NULL) ? strip_tags(nl2br($_POST['message'])) : 'No message';
// Your Email address
$message = wordwrap($message, 70);
$your_email = "bob@smith.com";
if(mail($your_email,$subject,$message,"From: $email")) echo 'Thanks for contacting us, we will reply shortly';
else echo 'An error occurred, and your contact info. could not be processed!';
}
?>