Here you go I have created an email form for you.
You need to make a few changes to your form in order for it to work -- the form should be changed to look like this. It is customised for your form but is easily altered for any form due to the simple array setup at the top.
<form method="post" action="the url to the script here" enctype="multipart/form-data">
<select name="title">
<option value="mr">Mr</option>
<option value="mrs">Mrs</option>
<option value="miss">Miss</option>
<option value="ms">Ms</option>
<option value="other">Other</option>
</select><br><br>
First name: <br>
<input type="text" name="firstname">
<br><br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
Email address:<br>
<input type="text" name="email">
<br><br>
Phone number:<br>
<input type="text" name="phone">
<br><br>
What suburb are you in?
<br>
<input name="suburb" type="text" />
<br><br>
What kind of work would you like to request a quote for?
<br>
<select name="work">
<option value="brick">Brick Work</option>
<option value="block">Block Work</option>
<option value="paving">Paving</option>
<option value="concrete">Concrete Pumping</option>
<option value="grout">Grout Pumping</option>
<option value="other">Other</option>
</select>
<br><br>
Please give an idea of the work to be done?
<textarea name="work2bdone" rows="15" cols="40">
</textarea>
<br><br>
What is the best day for us to contact you ?<br>
(Tick all that apply)<br><br>
<input type="checkbox" name="day[]" value="Monday">
Monday<br>
<input type="checkbox" name="day[]" value="Tuesday">
Tuesday<br>
<input type="checkbox" name="day[]" value="Wednesday">
Wednesday<br>
<input type="checkbox" name="day[]" value="Thursday">
Thursday<br>
<input type="checkbox" name="day[]" value="Friday">
Friday<br>
<input type="checkbox" name="day[]" value="Saturday">
Saturday<br>
<input type="checkbox" name="day[]" value="Sunday">
Sunday
<br><br>
What time is best for us to contact you?<br>
(Tick all that apply)<br><br>
<input type="checkbox" name="time[]" value="8-12">
8am-12am<br>
<input type="checkbox" name="time[]" value="12-5">
12am-5pm<br>
<input type="checkbox" name="time[]" value="5-9">
5pm-9pm<br>
<input type="checkbox" name="time[]" value="Any">
Anytime
<br><br>
Where did you hear about us?<br>
<select name="find">
<option value="google">Google</option>
<option value="friend">Through a friend</option>
<option value="busref">Through another business</option>
<option value="locpaper">Local newspaper</option>
<option value="natpaper">National newspaper</option>
<option value="buscard">Our business card</option>
<option value="car_graphic">Vehicle advertising</option>
<option value="other">Other</option>
</select>
<br><br>
<input type="submit" name="submit" value="Request Quote">
</form>
The PHP code is below -- I have also attached the whole script to this message.
<?php
$returnURL = 'http://www.example.com'; // The url to send the user back to if something went wrong
$successURL = 'http://www.example.com/success.html';// The url to send the user to if all goes well
$Temail = 'rakuli@oce.com';// Change it to anything you like -- is where the email will be sent to
$TemailBcc = 'random2@example.com'; // If you want to copy anyone in on all emails sent from the form, add them here separated by commas
$Semail = '"Solid Masonry - Online Contact Form" <%s>';
// If we didn't receive the correct input from the submit button, we'll send them away straight awa
if (isset($_POST['submit']))
{
//header ('Location: ' . $returnURL);
//exit();
// Set up an array of the elements to check and place in our message
// if you want the value to be mandatory, change the false to true -- don't change 4=>true though
$formInputs = array('title' => array('Title', true, array('mr', 'mrs', 'miss', 'ms', 'other')),
'firstname' => array('First Name', true),
'lastname' => array('Last Name', true),
'email' => array('Email Address', true, 3 => 'check_email'),
'phone' => array('Phone Number', false, 3 => 'ctype_digit'),
'suburb' => array('Suburb', false),
'work' => array('Work Type Request', false, array('brick', 'block', 'paving', 'concrete', 'grout', 'other')),
'work2bdone' => array('Work To Be Performed', false),
'day' => array('Best Day For Contact', false, array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), 4 => true),
'time' => array('Best Time For Contact', false, array('8-12', '12-5', '5-9', 'Any'), 4 => true),
'find' => array('Where You Heard About Us', false, array('google', 'friend', 'busref', 'locpaper', 'natpaper', 'buscard', 'car_graphic', 'other'))
);
// now loop throught that new array and sort everything out
$errors = array(); // Here is our errors list -- we will fill it as required
$errorMsg = 'Please check that you entered <strong>%s</strong> correctly';
$messageArray = array(); // Will hold the list of values to send out in the email
foreach ($formInputs as $pk => $pa)
{
if (!isset($_POST[$pk]) && $pa[1] === true)
{echo 'die ' . $_POST[$pk];
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
}
/***** Form inputs that have multiple available selections *****/
if ($pa[4] === true && is_array($_POST[$pk])) {
$msg = '';
foreach($_POST[$pk] as $val)
{
$msg .= in_array($val, $pa[2]) ? "\t\t" . htmlentities($val) . "<br />\n" : '';
}
if (!empty($msg))
$messageArray[] = '<strong>' . $pa[0] . "</strong> : <br />\n\n<br />" . $msg;
else if ($pa[1] === true)
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
} else if ($pa[1] === true && $pa[4] === true) {
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
}
/***** Form inputs that have a list of options to select from ******/
if (isset($pa[2]))
{
if (in_array($_POST[$pk], $pa[2]))
{
$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
} else if ($pa[1] === true)
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
}
$_POST[$pk] = trim($_POST[$pk]);
if (empty($_POST[$pk]) && $pa[1] === true)
{
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
} else if (empty($_POST[$pk]))
continue;
/**** Form inputs that require some sort of validation (phone numbers/email) ****/
if (isset($pa[3]))
{
if ($pa[3]($_POST[$pk]))
$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
else if ($pa[1] == true)
$errors[] = sprintf($errorMsg, $pa[0]);
continue;
}
// must be just a normal input so add it
$messageArray[] = '<strong>' . $pa[0] . '</strong> : ' . htmlentities($_POST[$pk]);
}
// If we didn't have any errors occur we can start to set up the message
if (!count($errors))
{
$Semail = sprintf($Semail, $_POST['email']);
$ob = md5(time() . 'masonboundary');
$ib = md5(time() . 'masonboundary2');
$headers = "From: ".$Semail."\n";
if (!empty($TemailBcc)) $headers .= "Bcc: ".$TemailBcc."\n";
$headers .= "Reply-To: <". $_POST['email'].">\n";
$headers .= "Return-Path: <" . $_POST['email'] . ">\n";
$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' +0000' . "\n";
$headers .= 'X-Mailer: Solid Masonry' . "\n";
$headers .= 'Mime-Version: 1.0' . "\n";
$headers .= 'Content-Type: multipart/alternative; boundary="' . $ob . '"' . "\n";
$headers .= 'Content-Transfer-Encoding: 7bit' . "\n";
$cnt = $content;
$content = "<title>$Semail</title>\n\n\n";
$content .= "<body style='font-family: verdana; font-size: 9pt;'>\n\n";
$content .= "<h1 style='font-size:1.1em'>Someone Has Contacted you!</h1>\n\n\n";
// loop through the messages
foreach ($messageArray as $msg)
$content .= $msg . "\n\n<br /><br />";
$content .= "Your Sincerely,\n\n<br /><br />";
$content .= "Your Website";
$message = strip_tags($content) . "\n" . '--' . $ob . "\n";
$message .= 'Content-Type: text/plain; charset=iso-8859-1' . "\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
$message .= strip_tags($content) . "\n" . '--' . $ob . "\n";
$message .= 'Content-Type: text/html; charset=charset=iso-8859-1' . "\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
$message .= $content . "\n" . '--' . $ob . '--';
mail($Temail, $subject, $message, $headers);
header('Location: ' . $successURL);
}
}
function check_email($email)
{ // First, we check that there's one @ symbol,
// and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not,
// it should be valid domain name
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
↪([A-Za-z0-9]+))$",
$domain_array[$i])) {
return false;
}
}
}
return true;
}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if (count($errors))
{
echo '<div style="border: solid 1px red;padding: 2em;">
<h1 style="font-size: 1.2em;">Some Errors Occurred</h1>
<ul>';
foreach ($errors as $err)
echo '<li>', $err, '</li>';
echo '</ul>
<a href="', $returnURL , '" onclick="window.history.back(); return false;">Go Back and try again</a>
</div>';
}
?>
</body>
</html>
This post has been edited by Rakuli: 18 February 2008 - 02:40 AM