Here is how to make a simple contact form with an HTML form and a simple PHP file to handle it.
This is the HTML code for a VERY basic form. This can be manipulated very easily to fit with styling etc, the only parts that must be kept in tact are the form and its elements.
<html>
<head>
</head>
<body>
<table>
<form name="main" method="post" action="contact.php">
<tr><td>Subject: </td><td><input name="subject" type="text" id="subject" size="50"></td></tr>
<tr><td>Name: </td><td><input name="name" type="text" id="name" size="50"></td></tr>
<tr><td>Email: </td><td><input name="email" type="text" id="email" size="50"></td></tr>
<tr><td>Message: </td><td><textarea name="message" cols="50" rows="4" id="message"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</body>
</html>
Here is the PHP component. (This would go in a file called "contact.php" because that was the "action" property specified in the HTML form)
<?php
// Get the email from the form
$email_from = $_POST['email'];
//Get the name from the form
$name = $_POST['name'];
// Get the subject from the form
$subject = $_POST['subject'];
// Get the message from the form
$message = $_POST['message'];
//Check if any fields were left blank...
if ($message == "" || $subject == "" || $name == "" || $email_from == "") {
echo 'You left one or more field blank. Please go back and fix this.';
}
else {
//Combine $name $email_from and $message
$body = "From: $name\n E-Mail: $email_from\n Message:\n $message";
// The email address to send the info. to
$to = 'your@email.com';
//Send the email
$sendEmail = mail($to, $subject, $body);
echo 'Your message was sent. Thank you!';
}
?>
Please note that this can be made more complex, but this is just a very simple, bare bones contact form in this thread.