Here is a simple contact us form, one thing I should edit later is to check if the email is valid but I don't have the time to edit this at the moment..
This was a old code I used for an old website, but I modified it to do version 2 of mccodes.
Enjoy and please give tips so I can get better, thanks.
Edit the email so it sends it to your email.
contact_us.php:
<?php
include "globals.php";
?>
<table align="center" width="45%" height="35%"><tr><td align="center" valign="top">
<center>
<font size="5" face="Arial Black">Contact Us</font>
<?php
$emailaddress = strip_tags($_POST['emailaddress']);
$message = strip_tags($_POST['message']);
$submit = $_POST['submit'];
if($submit)
{
if(strlen($emailaddress) < 5) {
die("
Please enter your email address.
Email address must be more than 5 characters. <meta http-equiv='refresh' content='2; url=contact_us.php'>");
}
else
if(strlen($message) < 10) {
die("
Please enter your message.
Message must be more than 10 characters. <meta http-equiv='refresh' content='2; url=contact_us.php'>");
}
else
//send activation email
$to = "
[email protected]";
$subject = "Contact Form";
$headers = "From: $emailaddress";
$body = $message;
//function to send email
if(mail($to, $subject, $body, $headers)){
echo "
[b]Message sent.[/b] <meta http-equiv='refresh' content='2; url=index.php'>";
}
else
die("
Error sending message");
}
?>
<form method='POST'>
<table align="center">
<tr>
<td>
Enter your email address:
<input style='width:50%;' type='text' name='emailaddress'>
</td></tr>
<tr><td>
Enter Your Message:
<textarea name='message' rows='15' cols='60'></textarea>
<input type='submit' name='submit' style='margin-left:50%;' value='Send Message' /></form>
</td>
</tr>
</table>
</center>
<?php
echo "</table>";
$h->endpage();
?>
Don't say anything about me using die, as I like to use it for things like this.
Thanks for reading and I hope you enjoy, for the critics please hit me with all you have, that is how I learn.