I have a from listed below that has a problem. I am wanting a web visitor to select multiple selections from the input “Interests” and then have those results emailed to me. Can someone tell me what I have done wrong and how I could fix it?
This should be easy for someone… just not me. Thanks in advance!
Todd
<!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>
<title>Multiple Select</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
/* ==============================================================================
DEFINES DEFAULT FORM FIELD VALUES
============================================================================== */
if(!isset($_POST['name'])) { $_POST['name'] = ""; }
if(!isset($_POST['interests'])) { $_POST['interests'] = ""; }
if(!isset($_POST['message'])) { $_POST['yourMessage'] = ""; }
// EMAIL NOT SENT BY DEFAULT
$emailSent = 0;
/* ==============================================================================
IF FORM HAS BEEN SUBMITTED, CHECK FOR ERRORS, IF NO ERRORS, SEND EMAIL
============================================================================== */
if(!isset($formError)) { $formError = array(); }
if (isset($_POST['submit'])) {
// SEND EMAIL IF NO ERRORS
if(count($formError) == 0) {
// IF NO MESSAGE TYPED, SET TO "NO MESSAGE ENTERED"
if (strlen(trim($_POST['message'])) == 0) {
$_POST['yourMessage'] = "No Message Entered by Visitor";
}
// CREATE EMAIL BODY
$theBody = $theBody . "Name: " . $_POST['name'] . "\
";
$theBody = $theBody . "Interests: " . $_POST['interests'] . "\
";
$theBody = $theBody . "Sent: " . date('m-d-Y', time()) . " " . date('g:i A', time()) . "\
\
";
// DEFINE EMAIL TO SEND TO
$emailTo = "test@domain.com";
$emailSubject = "Feedback";
// SEND EMAIL
mail($emailTo, $emailSubject, $theBody);
$emailSent = 1;
}
}
?>
<?php if($emailSent) { ?>
<!-- SUBMIT CONFIRMATION -->
Thank you.
<?php } else {
if(count($formError) == 0) { ?>
<?php } else { echo "<ul>"; foreach($formError as $e) { echo "<li class=\\"error\\">$e</li>"; } echo "</ul><br />"; }?>
<form action="multiple_select.php" method="post">
<table width="523" border="0" align="left" cellpadding="4" cellspacing="0">
<tr>
<td width="200" align="right" valign="top">Name:</td>
<td align="left" valign="middle"><input type="text" name="name" value="<?php echo $_POST['name'] ?>" size="24" tabindex="1"></td>
</tr>
<tr>
<td align="right" valign="top">Interests:</td>
<td align="left" valign="middle"><select name="interests[]" size="1" id="interests" tabindex="1" multiple="multiple">
<option selected="selected">Please Select</option>
<option value="Web Design"<?php if($_POST['interests'] == "Web Design") { echo " selected=\\"selected\\""; } ?>>Web Design </option>
<option value="CSS"<?php if($_POST['interests'] == "CSS") { echo " selected=\\"selected\\""; } ?>>CSS </option>
<option value="JavaScript"<?php if($_POST['interests'] == "JavaScript") { echo " selected=\\"selected\\""; } ?>>JavaScript </option>
<option value="PHP"<?php if($_POST['interests'] == "PHP") { echo " selected=\\"selected\\""; } ?>>PHP </option>
<option value="MySQL"<?php if($_POST['interests'] == "MySQL") { echo " selected=\\"selected\\""; } ?>>MySQL </option>
<option value="jQuery"<?php if($_POST['interests'] == "jQuery") { echo " selected=\\"selected\\""; } ?>>jQuery </option>
</select></td>
</tr>
<tr>
<td align="right" valign="top"> </td>
<td align="left" valign="middle"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>