Hi,
I just started writing some php last weekend. I started with a simple form I found in a tutorial last weekend and built on that. I am trying to get the results of the form to send in an email. The form emails but it does not include all the results. What am I doing wrong and how can I correct this?
Also I was wondering if you have any suggestions on how to make this form better, and where I can learn about the suggestions you are making.
Thanks for your help
Sue
html code:
<form method="post" action="sendmail.php">
<?php
session_register("SESSION");
?>
Last name: <input name="lname" size="20" maxlength="256">
<img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
First name: <input name="fname" size="20" maxlength="256"><br>
<p></p>
Address: <input name="address" size="35" maxlength="256">
<img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
City: <input name="city" size="35" maxlength="256">
<p></p>
State: <input name="state" size="2" maxlength="2">
<img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
Zip Code: <input name="zip" size="10" maxlength="20">
<p></p>
Email: <input name="email" size="35" maxlength="256"><br>
<p></p>
Phone: <input name="phone" size="14" maxlength="20">
<img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
FAX: <input name="fax" size="14" maxlength="20"><br><br>
<strong>What kind of comment would you like to
send?</strong><br><br>
<input type="radio" name="myradio" value="compliment"> Compliment<br>
<input type="radio" name="myradio" value="suggestion"> Suggestion<br>
<input type="radio" name="myradio" value="problem"> Problem<br>
<input type="radio" name="myradio" value="complaint"> Complaint<br>
<p><strong>What about us do you want to comment on?</strong></p>
<select name="more" size="1">
<option value="website" selected=""> Web Site</option>
<option value="prices"> Prices</option>
<option value="other"> Other</option>
</select> <img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
<input name="subject" size="40" maxlength="256">
<br>
<br>
<strong>Enter your comments in the space provided below:<br>
<textarea name="text" rows="5" wrap="physical" cols="42"></textarea></strong><br>
<br>
<input type="checkbox" name="contactrequested" value="contactrequested">
Please contact me as soon as possible regarding this matter.<br>
<p></p>
<input type="submit" name="submit" value="Submit" />
<img height="19" alt="" src="pics/smspacer.gif" width="22" border="0">
<input type="reset" value="Clear Form">
</form>
php code:
<?php
//valadate session
if (!session_is_registered("SESSION")){
$errors[] = "Invalid form submission";
}
//get all info
$lname = stripslashes($_POST['lname']) ;
$fname = stripslashes($_POST['fname']) ;
$address = stripslashes($_POST['address']) ;
$city = stripslashes($_POST['city']) ;
$state = stripslashes($_POST['state']) ;
$zip = stripslashes($_POST['zip']) ;
$email = stripslashes($_POST['email']) ;
$phone = stripslashes($_POST['phone']) ;
$fax = stripslashes($_POST['fax']) ;
if ($_POST['myradio']==compliment) ;
else if ($_POST['myradio']==suggestion) ;
else if ($_POST['myradio']==problem) ;
else if ($_POST['myradio']==complaint) ;
if ($_POST['more']==website) ;
else if ($_POST['more']==prices) ;
else if ($_POST['more']==other) ;
$subject = stripslashes($_POST['subject']) ;
$text = stripslashes($_POST['text']) ;
if ($_POST['contactrequested']==checked) ;
else if ($_POST['contactrequested']==unchecked) ;
$message = "lname: ".$lname . ". \n" ;
$message = "fname: ".$fname . ". \n" ;
$message = "address: ".$address . ". \n" ;
$message = "city: ".$city . ". \n" ;
$message = "state: ".$state . ". \n" ;
$message = "zip: ".$zip . ". \n" ;
$message = "email: ".$email . ". \n" ;
$message .= "phone: ".$phone . ". \n" ;
$message .= "fax: ".$fax . ". \n" ;
$message .= "myradio: ".$myradio . ". \n" ;
$message .= "more: ".$more . ". \n" ;
$message .= "subject: ".$subject . ". \n" ;
$message .= "text: ".$text . ". \n" ;
$message .= "contactrequested: ".$contactrequested . ". \n" ;
mail( "emailhere@blah.com", $subject, $message,"From: $email", $header ) ;
//to stop spammers
function safeHeaderFilter($string)
{
$badStrings = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"bcc:",
"cc:");
foreach (badStrings as $badstring) {
if ( strpos($string, $badstring) !== false ) {
notifyAdmin("Header injection attempt!", "Header injection attempt: found <<$badstring>> in <<$string>>.");
exit("Header injection attempt!");
}
}
return $string;
}
header ('Location: thankyou.htm') ;
exit () ;
?>