PDA

View Full Version : PHP Email form coding - require some help


tommisauce
11-29-2007, 03:00 PM
Hi folks,
I have created various email web forms, standard 'contact me' type ones (http://www.allgoonerdup.com/ContactUs/Contact.php) as well as some more indepth ones (http://www.vipink.co.uk/LimoService/VIPLimoBooking.php) However the coding is the same for input text areas. I now need to produce another web form but one of the questions has to have a drop down box - working example (http://dt7design.co.uk/Forms/Form.php) and the coding isn't working for this section - does anyone know how to code this properly. Any information would be appreciated.

Many thanks
TS

Code below:


<?php
if(isset($_POST['Submit'])) {
// begin by assuming that there is nothing suspicious
$suspect = false;

// pattern to check for suspicious content
$pattern = '/Content-type:|Bcc:|Cc:/i';

// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}

// check the $_POST array
isSuspect($_POST, $pattern, $suspect);

// check email address for illegal characters
// this is moved up from its position in the original script
$email = $_POST['email'];
if (eregi("\r",$email) || eregi("\n",$email)){
$suspect = true;
}

// if nothing suspicious has been found, process the form
if (!$suspect) {
$name = $_POST['name'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
$select = $_POST['select'];
if($name == '' or $email == '' or $comments == '' or $select == '') {
$err = true;
$msg = 'Please complete your name, email address and comments to submit the form.';
}
else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'Email: ' . $email . "\n";
$mailmsg.= 'Comments: ' . $comments . "\n";
if($mailing == 'true') {
$mailmsg.= 'I would like to be added to the mailing list';
}
// send the mail

if($mailing == 'true') {
$mailmsg.= 'I would like to be added to the mailing list';
}

/********************************** New section *********/
// prepare additional headers
$headers = "From: $email\r\n";
$headers .= "Reply-to: $email";
/************************************************** ******/

// send the mail - CHANGE THE LAST ARGUMENT TO $headers
if(mail('info@allgoonerdup.com','That new form you are sorting out', $mailmsg, $headers)) {


// although this will work, you should use a full URL to redirect the page
// for example: header('Location: http://www.example.com/thankyou.html');
header("Location: Thankyou.html");
}
}
}
// suspicious content has been found - send a neutral message
else {
$err = true;
$msg = 'Sorry, your message could not be sent';
}
}
?><!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>:: DT7 Form ::</title>
<script>

/*
Submit Once form validation-
Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
</script>


<link href="Forms.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php
if($err == true) {
echo '<p class="error">'. $msg . '</p>';
}
?>

<div id="Content">

<form id="Form" method="post" action="Form.php">
<form action="Form.php" method="POST" onSubmit="submitonce(this)">

<div id="Title">
<h2>Contact us </h2>
</div>
<div id="Name">
<label for="name">Name</label>
<input name="name" type="text" class="textbox" id="name" value="<?php echo $name; ?>" />
</div>
<div>
<label for="email">Email address</label>
<input name="email" type="text" class="textbox" id="email" value="<?php echo $email; ?>" />
</div>
<div>
<label for="comments">Comments</label>
<textarea name="comments" cols="30" rows="6" class="textbox" id="comments"><?php echo $comments; ?></textarea>
</div>
<div id="RadioBox">
<label></label>


<label>Favourite colour of a basketball hoop<br />
<select name="select"><?php echo $select; ?>"
<option>Green</option>
<option>Black</option>
<option>Red</option>
<option>Pink</option>
</select>
</label>
<label></label>

<label></label>

<p>&nbsp;</p>
</div>



<div id="Space"></div>
<div id="SubButt">
<input name="Submit" type="submit" class="SubmitBtn" value="Submit" />
</div>
</form>
</div>

</body>
</html>