Quite possible but you will have to use another form processor and not the built in one.
Here is the process:
1. Create the form page. Do NOT check the "Use built in form processor" checkbox. Set the action to "confirm.php" where "confirm.php" will be your "thank you" page. Set the encoding type to "multipart / Form data"
Add a combobox, with the possible choices of departments (persons). The combobox MUST be named "department".
You can use Radio buttons if you prefer, as long as their Group Name is "department"
2. Create a thankyou page, named "confirm". Set its extension to be .php
Add the following code in the page HTML, Start of page:
Code:
<?php
$subject = 'New Submission from our Multiple Department Website form';
$message = 'Values submitted from web site form to department: '.$_POST['department'];
$error_url = 'errorpage.php';
$address[Sales] = "sales@yourdomain.com";
$address[Warranty] = "warranty@yourdomain.com";
$address[Manufacturing] = "manufacturing@yourdomain.com";
$department_error = "Invalid department selection!<br>";// You can change this as required
if($_SERVER['REQUEST_METHOD'] != 'POST'){
$error = "No direct access allowed!";
include $error_url;
exit;
}
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
$upload_folder = isset($_POST['upload_folder']) ? $_POST['upload_folder'] : "uploads";
$upload_folder = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME'])."/".$upload_folder;
session_start();
if (isset($_SESSION['random_txt']) && md5($_POST['captcha_code']) == $_SESSION['random_txt']) {
unset($_POST['captcha_code'],$_SESSION['random_txt']);
}
else {
$error = "The verification code you have entered is not correct! Please go back and try again.";
include $error_url;
exit;
}
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
function check_email($string, $stringname)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
if (!preg_match($pattern, $string)) {
$error = "Your $stringname seems incorrect or missing!";
}
return $error;
}
$department = $_POST['department'];
$mailto = $address[$department];
if ($mailto == "") {
$error = $department_error;
}
$header = "From: ".$mailfrom."\r\n";
$header .= "Reply-To: ".$mailfrom."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
$prefix = rand(111111, 999999);
$i = 0;
while (list ($key, $val) = each ($_FILES))
{
if ($_FILES[$key]['name'] != "" and file_exists($_FILES[$key]['tmp_name']) and $_FILES[$key]['size'] > 0)
{
$upload_DstName[$i] = $prefix . "_" . str_replace(" ", "_", $_FILES[$key]['name']);
$upload_SrcName[$i] = $_FILES[$key]['name'];
$upload_Size[$i] = ($_FILES[$key]['size']);
echo "Uploaded File size = ".$upload_Size[$i] ."<br>]";
$upload_Temp[$i] = ($_FILES[$key]['tmp_name']);
$upload_Type[$i] = ($_FILES[$key]['type']);
$uploadlink[$i] = "$upload_folder/$upload_DstName[$i]";
$upload_fieldname[$i] = $key;
$upload_fieldname_final[$i] = ucwords(str_replace("_", " ", $key));
$fieldvalue[$i] = $uploadlink[$i];
if ($upload_Size[$i] >= $max_filesize)
{
$error .= "The size of $key (file: $upload_SrcName[$i]) is bigger than the allowed " . $max_filesize/1024 . " Kbytes!\n";
}
}
$i++;
}
$crack[0] = '\n';
$crack[1] = '\r';
$crack[2] = "%0a";
$crack[3] = "%0d";
$crack[4] = "content-type:";
$crack[5] = "to:";
$crack[6] = "cc:";
$crack[7] = "bcc:";
$crack[8] = "mime-version:";
$crack[9] = "x0a";
$crack[10] = "x0d";
foreach ($_POST as $key => $value)
{
for ($k = 0; $k < count($crack); $k++)
{
if (substr_count(strtolower($value), $crack[$k]))
{
$error .= "The field $key contained e-mail headers ($crack[$k]) in the value submitted. This seems to be a cracking attempt and the message has not been sent.!<br>";
}
}
}
if (($_POST['email'])) {
$error .= check_email($_POST['email'], "Email Address");
}
if ($error)
{
include $error_url;
exit;
}
$uploadfolder = basename($upload_folder);
for ($i = 0; $i < count($upload_DstName); $i++)
{
$uploadFile = $uploadfolder . "/" . $upload_DstName[$i];
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file($upload_Temp[$i] , $uploadFile);
chmod($uploadFile, 0644);
}
$internalfields = array ("submit", "reset", "filesize", "upload_folder", "send", "captcha_code", "form_to");
$message .= "\n";
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . "\n";
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . "\n";
}
}
}
if (count($upload_SrcName) > 0)
{
$message .= "\nThe following file have been uploaded:\n";
for ($i = 0; $i < count($upload_SrcName); $i++)
{
$message .= $upload_SrcName[$i] . " Link: " . $uploadlink[$i] . "\n";
}
}
mail($mailto, $subject, stripslashes($message), $header);
?> 3. In the aboce code, you need to change the following parts, according to your needs (only parts in red, make sure to keep quotes as seen):
$subject = 'New Submission from our Multiple Department Website form';// You can change this as required
$message = 'Values submitted from web site form to department: '.$_POST['department'];// You can change this as required
$error_url = 'errorpage.php'; // You can change this as required
$address[Sales] = "sales@yourdomain.com";
$address[Assistance] = "assistance@yourdomain.com";// You can change this as required
$address[Accounting] = "accounting@yourdomain.com";// You can change this as required
// Add as many similar lines as required
$department_error = "Invalid department selection!<br>";// You can change this as required
4. Create an errorpage named "errorpage". Needs to be .php Add your own template and the following text:
##error##
which, in case of error, will be replaced by the actual error.
"confirm" and "errorpage" can be changed as you like, as long as you replace these names also in the above code and settings.