<?php require "header.php"; ?>
<div id="contentSplit">
<!-- Splits the content div and sidebar div from the header -->
</div> <!-- Content Split -->
<div id="sidebarEqualizer">
<div id="contentEqualizer">
<div id="content">
<?php
$to='coolelemental@yahoo.com';
$messageSubject='Just Computers Inquiry';
$confirmationSubject='Your message has been received';
$confirmationBody='Thank you for contacting us, we will try our best to respond within 48 hours.';
$name='';
$email='';
$body='';
$displayForm=true;
if ($_POST) {
$email=stripslashes($_POST['email']); // No slashes allowed
$body=stripslashes($_POST['body']); // No slashes allowed
// Let's validate our e-mail address
$valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
$crack=eregi("(\r|\n) (to:|from:|cc:|bcc:)",$body);
if ($email && $body && $valid && !$crack){
if (mail($to,$messageSubject,$body,'From: '.$email."\r\n")
&& mail($email,$confirmationSubject,$confirmationBody.$body,'From: '.$to."\r\n")){
$displayForm=false;
?>
<h1>Your e-mail has been sent.</h1>
<p>Thank you for contacting us, we will try our best to respond within 48 hours.</p>
<p>In addition, a confirmation copy was sent to your e-mail address.</p>
<p>Below is a copy of your message.</p>
<?php
echo '<div id="messageDisplay"><p>'.htmlspecialchars($body).'</p></div>';
} else { // Your message could not be sent
?>
<p>
Something went wrong when the server tried to send your message.
This is usually due to a server error, and is probably not your fault.
We apologise for any inconvenience caused.
</p>
<?php
}
} else if ($crack) { // Someone is trying to crack
?>
<p><strong>
Your message contained e-mail headers within the message body.
This seems to be a cracking attempt and the message has not been sent.
</strong></p>
<?php
} else { // The form is not complete.
?>
<p><strong>
Your message could not be sent.
You must include both a valid e-mail address and a message.
</strong></p>
<?php
}
}
if ($displayForm) {
?>
<h1>Contact Us</h1>
<!-- Begin Form Elements -->
<fieldset>
<form action="contactus.php" method="post">
<p><strong>Name:</strong> <input type="text" name="name" id="name" /></p>
<p><strong>E-mail:</strong><input type="text" name="email" id="email"
value="<?php echo htmlspecialchars($email); ?>" />
<span class="emailConfirmationMoveOver">(a confirmation e-mail will be sent to you.)</span></p>
<p><strong>Message:</strong><textarea name="body" id="body" rows="" cols="1" wrap="hard"><?php echo htmlspecialchars($body); ?></textarea>
<input type="submit" id="submit" value="Send Reply" class="submitButton" /></p>
</form>
</fieldset>
<!-- End Form Elements -->
<?php
}
?>
</div> <!-- Content -->
</div> <!-- End contentEqualizer -->
<?php require "sidebar.php";?>
<?php require "footer.php"; ?>
I'm getting stuck trying to figure out HOW and WHERE to place the $name variable, I want a user to be able to send their name alonside their email address for future reference.
Here is the URL: Website
Functionality is ace, just want to know how to add an additional field, such as a name field. Do note that even though there is a name field on the page, it is not being processed right now. I'd like the name to be a required field as well, so that people can be addressed by their names.
