I didn't look through your code, but you can just use this one I made. It works (I think  ):
Code:
<style type="text/css">
body {
font-family: arial;
}
.contactForm {
border: 1px solid #ccc;
padding: 15px;
margin: auto;
}
.contactForm td {
padding: 0 55px 10px 0;
}
h1 {
font-size: 23px;
margin: 0;
}
.text {
border: 1px solid #999;
width: 260px;
height: 25px;
}
textarea {
border: 1px solid #999;
width: 420px;
height: 200px;
}
.error {
color: #f00;
font-size: 13px;
font-weight: bold;
}
</style>
PHP Code:
<?php
// turn off error reporting error_reporting(0);
// user submitted form variables $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $submit = $_POST['submit'];
if(isset($submit)) {
if(!$name) $error1 = "<span class='error'>Required: Name</span><br />"; if (!$email) $error2 = "<span class='error'>Required: Email</span><br />"; if(strpos($email, '@') == 0) $error3 = "<span class='error'>Invalid Email</span><br />"; if(!$subject) $error4 = "<span class='error'>Required: Subject</span><br />"; if(!$message) $error5 = "<span class='error'>Required: Message</span><br />";
if(strpos($email, '@') == 1) {
if($name && $email && $subject && $message) { // send email $sendMail = mail("ENTER - YOUR - EMAIL - HERE", $subject, $message, "from: $email");
// display success or fail message if($sendMail) echo "<div style='border:2px solid green;width:300px;margin:auto;margin-bottom:25px;text-align:center;padding:5px;'>Your message has been sent.</div>"; else echo "<div style='border:2px solid red;width:300px;margin:auto;margin-bottom:25px;text-align:center;padding:5px;'>Message could not be sent.</div>";
}
}
}
?>
HTML Code:
<form action="" method="POST">
<table class="contactForm">
<tr>
<td> </td>
<td><h1>Contact Us</h1></td>
</tr>
<tr>
<td><label>Name:</label></td>
<td><?php echo $error1; ?><input type="text" class="text" name="name" value="<?php echo $name; ?>" /></td>
</tr>
<tr>
<td><label>Email:</label></td>
<td><?php echo $error2; ?><?php echo $error3; ?><input type="text" class="text" name="email" value="<?php echo $email; ?>" /></td>
</tr>
<tr>
<td><label>Subject:</label></td>
<td><?php echo $error4; ?><input type="text" class="text" name="subject" value="<?php echo $subject; ?>" /></td>
</tr>
<tr>
<td><label>Message:</label></td>
<td><?php echo $error5; ?><textarea name="message"><?php echo $message; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Send Message" /></td>
</tr>
</table>
</form>
Just replace "ENTER - YOUR - EMAIL - HERE" with your email address
BTW I didn't add any filtering to sanitize input from the user, you may want to add that for security reasons especially if this is going to insert the emails into a database in addition to mailing them to you.
Last edited by Marik; 05-05-2010 at 07:46 PM..
|