Jo Mutch
12-16-2008, 07:39 PM
Hi, just learning php so please be gentle with me.
I have created a form and its associated php handler but am unable to make the form submit the fields in the form. Any suggestions would be much appreciated
The form is sent to who ever is selected but the senders details are not included other than the email address and would like the other details from the form to be included. I have probably done something simple but for the life of me I cant find it or make it work.
<form action="" method="POST">
<b> </b>
<table width="85%" border="0" align="center">
<tr>
<td width="40%" valign="top"><b>Please enter your name:</b></td>
<td width="60%" valign="top">
<input type="text" name="name" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please choose a contact: </b> </td>
<td width="60%" valign="top">
<select name="contact">
<option value="default">Choose who to contact</option>
<option value="1"> Membership </option>
<option value="2"> Our Way </option>
<option value="3"> Meets Co-Ordinator </option>
<option value="4"> Trades Officer </option>
<option value="5"> Treasurer </option>
<option value="6"> Forum Adminsitration </option>
<option value="7"> Publicity </option>
<option value="8"> Secretary </option>
<option value="9"> Information </option>
</select>
</td>
</tr>
<tr>
<td width="40%" valign="top"><b>Please enter a subject:</b></td>
<td width="60%" valign="top">
<input type="text" name="subject" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please enter your email address:</b></td>
<td width="60%" valign="top">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please enter your message: </b></td>
<td width="60%" valign="top">
<textarea name="message" cols="60" rows="10">
</textarea>
</td>
</tr>
<tr>
<td width="40%"> </td>
<td width="60%" valign="top">
<input type="submit" value="Submit" name="submit_1">
<input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit_1'])) {
$name = $_POST['name'];
$contact = $_POST['contact'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$error = "";
$headers = 'From:'.' '. $email;
if($name=="") $error.="*Please enter a name"."<br>";
if($subject=="") $error.="*Please enter a subject"."<br>";
if($email=="") $error.="*Please enter a email"."<br>";
if($message=="") $error.="*Please enter a message"."<br>";
switch ($contact){
case 1:
$contact = "membership@sbmcc.co.uk"; // Shaun //
break;
case 2:
$contact = "ourway@sbmcc.co.uk"; // Jo //
break;
case 3:
$contact = "meets@sbmcc.co.uk"; // Barry //
break;
case 4:
$contact = "trades@sbmcc.co.uk"; // Paul //
break;
case 5:
$contact = "treasurer@sbmcc.co.uk"; // Wal //
break;
case 6:
$contact = "webmaster@sbmcc.co.uk"; // Ian //
break;
case 7:
$contact = "publicity@sbmcc.co.uk"; // Trev //
break;
case 8:
$contact = "secretary@sbmcc.co.uk"; // Mike //
break;
case 9:
$contact = "info@sbmcc.co.uk"; // Mike //
break;
default:
$contact = "info@sbmcc.co.uk"; // Mike //
break;
}
if($error==""){
if(mail($contact, $subject, $message, $headers)){
echo "<p><b><font color=#f00>Thank You $name</b></p><p>We will be in touch as soon as possible.</font></p><br /><br />";
}
else {
echo " <p><b><font color=#f00>Email failed to send</font></b></p><br /><br /> ";
}
}
else{
echo "<div align='center'>". $error ."</div>";
}
}
else ;
?>
I have created a form and its associated php handler but am unable to make the form submit the fields in the form. Any suggestions would be much appreciated
The form is sent to who ever is selected but the senders details are not included other than the email address and would like the other details from the form to be included. I have probably done something simple but for the life of me I cant find it or make it work.
<form action="" method="POST">
<b> </b>
<table width="85%" border="0" align="center">
<tr>
<td width="40%" valign="top"><b>Please enter your name:</b></td>
<td width="60%" valign="top">
<input type="text" name="name" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please choose a contact: </b> </td>
<td width="60%" valign="top">
<select name="contact">
<option value="default">Choose who to contact</option>
<option value="1"> Membership </option>
<option value="2"> Our Way </option>
<option value="3"> Meets Co-Ordinator </option>
<option value="4"> Trades Officer </option>
<option value="5"> Treasurer </option>
<option value="6"> Forum Adminsitration </option>
<option value="7"> Publicity </option>
<option value="8"> Secretary </option>
<option value="9"> Information </option>
</select>
</td>
</tr>
<tr>
<td width="40%" valign="top"><b>Please enter a subject:</b></td>
<td width="60%" valign="top">
<input type="text" name="subject" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please enter your email address:</b></td>
<td width="60%" valign="top">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td width="40%" valign="top">
<b> Please enter your message: </b></td>
<td width="60%" valign="top">
<textarea name="message" cols="60" rows="10">
</textarea>
</td>
</tr>
<tr>
<td width="40%"> </td>
<td width="60%" valign="top">
<input type="submit" value="Submit" name="submit_1">
<input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit_1'])) {
$name = $_POST['name'];
$contact = $_POST['contact'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$error = "";
$headers = 'From:'.' '. $email;
if($name=="") $error.="*Please enter a name"."<br>";
if($subject=="") $error.="*Please enter a subject"."<br>";
if($email=="") $error.="*Please enter a email"."<br>";
if($message=="") $error.="*Please enter a message"."<br>";
switch ($contact){
case 1:
$contact = "membership@sbmcc.co.uk"; // Shaun //
break;
case 2:
$contact = "ourway@sbmcc.co.uk"; // Jo //
break;
case 3:
$contact = "meets@sbmcc.co.uk"; // Barry //
break;
case 4:
$contact = "trades@sbmcc.co.uk"; // Paul //
break;
case 5:
$contact = "treasurer@sbmcc.co.uk"; // Wal //
break;
case 6:
$contact = "webmaster@sbmcc.co.uk"; // Ian //
break;
case 7:
$contact = "publicity@sbmcc.co.uk"; // Trev //
break;
case 8:
$contact = "secretary@sbmcc.co.uk"; // Mike //
break;
case 9:
$contact = "info@sbmcc.co.uk"; // Mike //
break;
default:
$contact = "info@sbmcc.co.uk"; // Mike //
break;
}
if($error==""){
if(mail($contact, $subject, $message, $headers)){
echo "<p><b><font color=#f00>Thank You $name</b></p><p>We will be in touch as soon as possible.</font></p><br /><br />";
}
else {
echo " <p><b><font color=#f00>Email failed to send</font></b></p><br /><br /> ";
}
}
else{
echo "<div align='center'>". $error ."</div>";
}
}
else ;
?>