...

View Full Version : elements in form not sending to mail



Jo Mutch
12-16-2008, 08: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%">&nbsp; </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 ;
?>

Fumigator
12-16-2008, 09:10 PM
Can you clarify--

You DO get an email sent? It's just the wrong/missing stuff in the email that's the problem?

Or is the email not being sent at all?

Jo Mutch
12-16-2008, 09:39 PM
Sorry for lack of clarification. I do get an email sent but it only contains the message section and none of the other information (Name, Subject etc)

Fumigator
12-16-2008, 10:04 PM
To make sure your form data is coming across successfully, do


echo "<pre>".print_r($_POST)."</pre>";


Make sure your $subject variable contains the correct value by echoing it.

logictrap
12-16-2008, 10:39 PM
I don't see anywhere in your code where you do anything with 'name' other than check if it's there.

Jo Mutch
12-16-2008, 11:08 PM
To make sure your form data is coming across successfully, do


echo "<pre>".print_r($_POST)."</pre>";



Anywhere in particular, I suppose it should go near the top. I'll give it a go and see what happens.

Just tried adding the echo and have come up with the following


Array ( [name] => Harry the Spider (Test) [contact] => 2 [subject] => Test [email] => elizium@ladt.org [message] => Test [submit_1] => Submit )

1


The above appears on the webpage contact form rather than transferring the information in the fields to
the email that is to be sent out. Very frustrating. Suppose I still have a lot to learn about the php lark



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum