Simple contact form 05-13-2013, 11:07 PM
#1
Here is a tutorial I threw together quickly on how to code a simple PHP contact form for your website - thought it would be useful since most websites contain something like this.
contact.html
process.php
There you go, a fully-functional PHP contact form. Now you can go back and style the contact.html page to your liking.
contact.html
Code:
<form method="POST" action="process.php">
<input type="text" name="name" size="19" placeholder="Name"><br>
<br>
<input type="text" name="email" size="19" placeholder="Email"><br>
<br>
<textarea rows="9" name="message" cols="30" placeholder="Message"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</form>process.php
Code:
<?php
if(isset($_POST['submit'])) {
$to = "slim@thug.pw"; // your email for receiving submissions
$subject = "You have a new submission"; // subject of the emails sent to you
$name_field = $_POST['name']; // process name
$email_field = $_POST['email']; // process email
$message = $_POST['message']; // process message
$body = "<strong>From:<strong> $name_field\n <strong>E-Mail:</strong> $email_field\n <strong>Message:<strong>\n $message"; // message format as it will be sent to you
echo "Thank you for your submission! "; // success message
mail($to, $subject, $body);
} else {
echo "There was an error, please try again!"; // error message
}
?>There you go, a fully-functional PHP contact form. Now you can go back and style the contact.html page to your liking.
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)





![[Image: HWV7adO.jpg]](http://i.imgur.com/HWV7adO.jpg)