… and it probably involves the use of function (which means I need a refresher or two…)
Anyways, its a form that submits to itself, checks that the 4 fields are filled out, then sends an email.
It’s a whole lot of if/not if statements, and the only thing that’s not in there that I would like to to validate the email syntax.
Any advise for a learning programmer?
[code=php]
<?php
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Mon, 1 Jan 2000 00:00:00 GMT”); // Date in the past
?><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>AIC-Wisconsin – Contact Us</title>
<link rel=”stylesheet” type=”text/css” href=”../admin/loginmodule.css”>
</head>
<body>
<h1>Contact Us</h1>
<?php
include_once (‘nav.php’);
if (isset($_POST[‘submit’])){
// form has been submitted
$name = $_POST[‘name’];
$email = $_POST[’email’];
$subject = $_POST[‘subject’];
$messageBody = $_POST[‘messageBody’];
if (!isset($name) || $name == “”){
$message = “Please enter your name.<br />”;
}
if (!isset($email) || $email == “”){
$message = “Please enter an email address.<br />”;
}
if (!isset($subject) || $subject == “”){
$message .= “Please enter a subject.<br />”;
}
if (!isset($messageBody) || $messageBody == “”){
$message .= “Please enter a message.<br />”;
}
if ($message == “”) {
//send mail
$now = date(‘l F jS Y h:i:s A’);
$dateString = “rn rn This emal was generated on $now”;
$to = “[email protected]”;
$from=”AIC-Wisconsin”;
$messageBody =wordwrap($messageBody, 100);
$messageBody .= $dateString;
$headers = “From: $from” . “rn” . “Reply-To: $email” . “rn” .
‘X-Mailer: PHP/’ . phpversion();
// Send Mail
$sendmail = mail($to, $subject, $messageBody, $headers);
if ($sendmail) {
$name = “”;
$email = “”;
$subject = “”;
$messageBody = “”;
$timestamp = “<p>Your email was sent at $now.</p>”;
}
else {
echo mysql_error();
}
}
else {
// dont send mail
$validate = mysql_error();
}
} // end: if (isset($_POST[‘submit’])){
else {
// form not submitted
} // end else
?>
<p style=”color:#C00;”><?php echo $message; ?></p>
<p><?php echo $validate; ?></p>
<form id=”contact” name=”contactForm” method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’] ?>”>
<table width=”400″ border=”0″ cellpadding=”2″ cellspacing=”0″>
<tr>
<td width=”112″><strong>Name</strong></td>
<td width=”188″><input name=”name” type=”text” class=”textfield” id=”name” size=”50″ value=”<?php echo $name; ?>” /></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td><input name=”email” type=”text” class=”textfield” id=”email” size=”50″ value=”<?php echo $email; ?>” /><br />
<em>(your email address will be kept private)</em></td>
</tr>
<tr>
<td width=”112″><strong>Subject</strong></td>
<td width=”188″><input name=”subject” type=”text” class=”textfield” id=”subject” size=”50″ value=”<?php echo $subject; ?>” /></td>
</tr>
<tr>
<td valign=”top”><strong>Message</strong></td>
<td><textarea name=”messageBody” type=”text” class=”textfield” id=”message” cols=”47″ rows=”10″><?php echo $messageBody; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type=”submit” name=”submit” value=”Submit” /></td>
</tr>
</table>
</form>
<p><?php echo $timestamp; ?></p>
</div></div>
</body>
</html>