Adding A Drop Down Email Address Recipient to A Contact Form

[font=verdana][size=medium]I have a contact form that works perfectly … the forms results are currently being sent to one email address.

There is a drop down “Contact” field on the form, and I would like the forms results to be sent to the persons email address selected from the drop down.

The php lines are $Contact = $_POST[“Contact”]; and $msg .= “Contact: $Contact\n”;

Drop Down Names Drop Down Email Addresses
Keith [email protected]
John [email protected]
Mike [email protected]

Would someone please copy the entire php script below, and paste it into a reply with the drop down names selection function added?

There’s a mail headers & mail section at the very bottom, and I think possibly adding another mail header, that references the drop down selection field “Contact” might be close, but honestly I don’t have a clue as to what I’m doing.

I can spend all day on this, and still not get it right. However, if I can see how it’s written … I can add the rest email addresses which I didn’t list above.

Thank You![/size][size=18px]


[/size][/font][size=small][php][font=verdana][/size][size=18px]<?php$d = date(“m-d-y H:i:s”);// assign incomming data$CustomerStatus = $_POST[“CustomerStatus”];$Contact = $_POST[“Contact”];$Name = $_POST[“Name”];$an = str_replace(" ", “”, $Name);$Company = $_POST[“Company”];$Phone = $_POST[“Phone”];//$office = $_POST[“office”];$Fax = $_POST[“Fax”];$Email = $_POST[“Email”];$ProjectName = $_POST[“ProjectName”];$ProofType = $_POST[“ProofType”];$Pages = $_POST[“Pages”];$Quantity = $_POST[“Quantity”];$ColorFrontBack = $_POST[“ColorFrontBack”];$FlatSize = $_POST[“FlatSize”];$FoldedSize = $_POST[“FoldedSize”];$StockText = $_POST[“StockText”];$StockCover = $_POST[“StockCover”];$LabelStock = $_POST[“LabelStock”];$Coating = $_POST[“Coating”];$Bindery = $_POST[“Bindery”];$Additional = $_POST[“Additional”];$FileType = $_POST[“FileType”];$ApplicationType = $_POST[“ApplicationType”];$group1 = $_POST[“group1”];$group2 = $_POST[“group2”];$group3 = $_POST[“group3”];$redirect = $_POST[“redirect”]; [/size][/font][/php][/size][size=small]// http://www.mysite.com/
//$subject = $_POST[“Subject”]; [/size][size=small]// Subject is hard coded in the config area, you can use either, comment out the one you dont want to use

/* ************* Begin Configuration ************* */
$relocate = “http://www. mysite.com/”; // insert your relocation url here
$home = “http://www. mysitehome.com/”;
$MOVE_TO_PATH = ‘/home/content/x/y/x/xyzaaa/html/FileUpload/’;
$PATH_TO_DIR = ‘http://www. mysitehome.com/FileUpload/’;
// The following values are used to verify_uploaded_file() as the sizes and types that can be uploaded.
$UPLOAD_TYPES[‘PSD’] = 1; // Allow .psd files
$UPLOAD_TYPES[‘JPG’] = 1; // Allow .jpg files (definition must be upper case)
$UPLOAD_TYPES[‘JPEG’] = 1; // Allow .jpeg files
$UPLOAD_TYPES[‘AI’] = 1; // Allow .ai files
$UPLOAD_TYPES[‘EPS’] = 1; // Allow .eps files
$UPLOAD_TYPES[‘PDF’] = 1; // Allow .pdf files
$UPLOAD_TYPES[‘GIF’] = 1; // Allow .gif files
$UPLOAD_TYPES[‘PNG’] = 1; // Allow .png files
$UPLOAD_TYPES[‘DOC’] = 1; // Allow .doc files
$UPLOAD_TYPES[‘XLS’] = 1; // Allow .xls files
$UPLOAD_TYPES[‘ZIP’] = 1; // Allow .zip files
$UPLOAD_TYPES[‘SIT’] = 1; // Allow .sit files
$UPLOAD_TYPES[‘FLA’] = 1; // Allow .fla files
$UPLOAD_SIZES[‘max’] = 180000000; // Maximum size – Make sure the file is under 180 MB : 180,000,000 = 180 MB
$UPLOAD_SIZES[‘min’] = 0; // Minimum size – Arbitrary small file size to distinguish between no file and file submission

$sender_name = “My Site Order”;
$sender_email = "[email protected]";
$mailheaders = “Content-Type: text/plain; charset=us-ascii\nFrom: $sender_name <$sender_email>\nReply-To: <$sender_email>\nReturn-Path: <$sender_email>\nX-Mailer: PHP”;

//$to = “[email protected] mysitehome.com”;
$to = “[email protected] mysitehome.com”;
$subject = “Order”;

$msg ="$d\n\n";
$msg .= “CustomerStatus: $CustomerStatus\n”;
$msg .= “Contact: $Contact\n”;
$msg .= “Name: $Name\n”;
$msg .= “Company: $Company\n”;
$msg .= “Phone: $Phone\n”;
$msg .= “Fax: $Fax\n”;
$msg .= “Email: $Email\n”;
$msg .= “ProjectName: $ProjectName\n”;
$msg .= “ProofType: $ProofType\n”;
$msg .= “Pages: $Pages\n”;
$msg .= “Quantity: $Quantity\n”;
$msg .= “ColorFrontBack: $ColorFrontBack\n”;
$msg .= “FlatSize: $FlatSize\n”;
$msg .= “FoldedSize: $FoldedSize\n”;
$msg .= “StockText: $StockText\n”;
$msg .= “StockCover: $StockCover\n”;
$msg .= “LabelStock: $LabelStock\n”;
$msg .= “Coating: $Coating\n”;
$msg .= “Bindery: $Bindery\n”;
$msg .= “Additional: $Additional\n”;
$msg .= “FileType: $FileType\n\n”;
$msg .= “ApplicationType: $ApplicationType\n”;
$msg .= “group1: $group1\n”;
$msg .= “group2: $group2\n”;
$msg .= “group3: $group3\n”;

$success_block = “

Thank you for submitting your information. We will review your information and get back to you within a day or two.



”;

/* ************* End Configuration ************* */

// fn to Check file size and type
function verify_uploaded_file($strName, $intSize) {
if ($intSize < $GLOBALS[‘UPLOAD_SIZES’][‘min’] || $intSize > $GLOBALS[‘UPLOAD_SIZES’][‘max’]) {
return -1;
}
$arrSegments = split(’[.]’, $strName); // allow and check multiple dots in filename
$strExtension = $arrSegments[count($arrSegments) - 1];
if ($GLOBALS[‘UPLOAD_TYPES’][strtoupper($strExtension)] != 1) {
return -2; // File type not defined/allowed
}
return 1; // All tests have passed; this file is valid, return true
} // end fn

function get_extension($filename){
$arrSegments = split(’[.]’, $filename);
$extension = $arrSegments[count($arrSegments) - 1];
return $extension;
}

$head0 = "

Image Upload


";

$head1 = "

\n \n \n\n \n \n
Image Upload
";

$head2 = "

";

// echo $head0;
// echo $head1;

/* begin file upload work */

if ($HTTP_POST_FILES[‘upload_file1’][‘name’] != “”) {

//echo 'File 1: ’ . $HTTP_POST_FILES[‘upload_file1’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file1’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file1’][‘name’], $HTTP_POST_FILES[‘upload_file1’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file1’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file1’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file1’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file1’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file1’][‘name’]);
$newname = “$an” . “-1” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file1’][‘name’],$MOVE_TO_PATH . $newname);
$msg .= “$PATH_TO_DIR” . “$newname\n”;
//echo ‘

’ . $HTTP_POST_FILES[‘upload_file1’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname . ’ target="_blank">View File #1 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #1
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file2’][‘name’] != “”) {
//echo '

File 2: ’ . $HTTP_POST_FILES[‘upload_file2’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file2’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file2’][‘name’], $HTTP_POST_FILES[‘upload_file2’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file2’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file2’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file2’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file2’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file2’][‘name’]);
$newname2 = “$an” . “-2” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file2’][‘name’],$MOVE_TO_PATH . $newname2);
$msg .= “$PATH_TO_DIR” . “$newname2\n”;
//echo ‘

’ . $HTTP_POST_FILES[‘upload_file2’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname2 . ’ target="_blank">View File #2 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #2
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file3’][‘name’] != “”) {
//echo '

File 3: ’ . $HTTP_POST_FILES[‘upload_file3’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file3’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file3’][‘name’], $HTTP_POST_FILES[‘upload_file3’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file3’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file3’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file3’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file3’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file3’][‘name’]);
$newname3 = “$an” . “-3” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file3’][‘name’],$MOVE_TO_PATH . $newname3);
$msg .= “$PATH_TO_DIR” . “$newname3\n”;
//echo ‘

’ . $HTTP_POST_FILES[‘upload_file3’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname3 . ’ target="_blank">View File #3 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #3
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file4’][‘name’] != “”) {
//echo '

File 4: ’ . $HTTP_POST_FILES[‘upload_file4’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file4’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file4’][‘name’], $HTTP_POST_FILES[‘upload_file4’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file4’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file4’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file4’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file4’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file4’][‘name’]);
$newname4 = “$an” . “-4” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file4’][‘name’],$MOVE_TO_PATH . $newname4);
$msg .= “$PATH_TO_DIR” . “$newname4\n”;
//echo ‘

’ . $HTTP_POST_FILES[‘upload_file4’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname4 . ’ target="_blank">View File #4 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #4
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file5’][‘name’] != “”) {
//echo '

File 5: ’ . $HTTP_POST_FILES[‘upload_file5’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file5’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file5’][‘name’], $HTTP_POST_FILES[‘upload_file5’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file5’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file5’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file5’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file5’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file5’][‘name’]);
$newname5 = “$an” . “-5” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file5’][‘name’],$MOVE_TO_PATH . $newname5);
$msg .= “$PATH_TO_DIR” . “$newname5\n”;
// echo ‘

’ . $HTTP_POST_FILES[‘upload_file5’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname5 . ’ target="_blank">View File #5 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #5
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file6’][‘name’] != “”) {
//echo '

File 6: ’ . $HTTP_POST_FILES[‘upload_file6’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file6’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file6’][‘name’], $HTTP_POST_FILES[‘upload_file6’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file6’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file6’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file6’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file6’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file6’][‘name’]);
$newname6 = “$an” . “-6” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file6’][‘name’],$MOVE_TO_PATH . $newname6);
$msg .= “$PATH_TO_DIR” . “$newname6\n”;
// echo ‘

’ . $HTTP_POST_FILES[‘upload_file6’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname6 . ’ target="_blank">View File #6 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #6
\n\n”;
} // end check file requirements

if ($HTTP_POST_FILES[‘upload_file7’][‘name’] != “”) {
//echo '

File 7: ’ . $HTTP_POST_FILES[‘upload_file7’][‘name’] . ‘’ . ‘
Size: ’ . $HTTP_POST_FILES[‘upload_file7’][‘size’] . ‘
’;
$intResult = verify_uploaded_file($HTTP_POST_FILES[‘upload_file7’][‘name’], $HTTP_POST_FILES[‘upload_file7’][‘size’]);
if ($intResult != 1) {
$msg_base = $HTTP_POST_FILES[‘upload_file7’][‘name’] . ’ is unacceptable.

’;
if ($intResult == -1) {
$send = “false”;
die($msg_base . ‘Reason: File size is too large or non-existent. Please use your Back button to try again.

’);
} elseif ($intResult == -2) {
$send = “false”;
die($msg_base . ‘Reason: File type is not allowed. Please use your Back button to try again.

’);
}
}

if (! move_uploaded_file($HTTP_POST_FILES[‘upload_file7’][‘tmp_name’], $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file7’][‘name’]) ) {
$send = “false”;
die(‘You did not upload a file or the file could not be moved to ’ . $MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file7’][‘name’]);
} else {
$ext = get_extension($HTTP_POST_FILES[‘upload_file7’][‘name’]);
$newname7 = “$an” . “-7” . “.$ext”;
rename ($MOVE_TO_PATH . $HTTP_POST_FILES[‘upload_file7’][‘name’],$MOVE_TO_PATH . $newname7);
$msg .= “$PATH_TO_DIR” . “$newname7\n”;
// echo ‘

’ . $HTTP_POST_FILES[‘upload_file7’][‘name’] . ’ was successfully uploaded.

<a href=’ . $PATH_TO_DIR . $newname7 . ’ target="_blank">View File #7 Here

’;
$send = “true”;
}

} else {
//echo “No attempt to upload file #7
\n\n”;
} // end check file requirements

// echo “$success_block”;
//echo “

<a href=“javascript: history.go(-1)”>Back | Home”;

$my_email = ‘[email protected]’;
$mailheaders2 = “Content-Type: text/plain; charset=us-ascii\nFrom: My Printing Company <$my_email>\nReply-To: <$my_email>\nReturn-Path: <$my_email>\nX-Mailer: PHP”;

if ($send != “false”) {
mail($to, $subject, $msg, $mailheaders); // mail sent to admin
mail($_POST[‘Email’], $subject, ‘Thanks we received your info’,$mailheaders2); // confirmation email
header(“Location: $relocate”);
}

?>
[/size][size=small]

Thanks!

If you use “php” button in the toolbar to format php code, your code would look like this:
[php]<?php
echo ‘Hello World!’;
?>[/php]

Add this code to your html form:

[php]Contact:

Keith John Mike [/php]

And then modify this line in your php code:
[php]$to = “[email protected] mysitehome.com”;[/php]

to this:
[php]$to = $_POST[“to”];
if(!in_array(array("[email protected]","[email protected]","[email protected]"))) $to = "[email protected]"’;[/php]

When I added

[font=courier new][size=13px]$to [/size][/font]= $_POST[“to”];
if(!in_array(array("[email protected]","[email protected]","[email protected]"))) $to = "[email protected]"’;

[size=13px][font=arial]I get this error:[/font][/size]
[font=arial][/font]
[font=arial][size=13px][font=Times][/size][size=medium]Parse error[/size][/font][/size][size=13px][font=Times][/size][size=medium]: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in[/size][/font][/size][size=13px][font=Times][/size][size=medium] [/size][/font][font=Times][/size][size=medium]/home/content/v/n/d/vndink/html/UP/orders.php[/size][/font][font=Times][/size][size=medium] [/size][/font][font=Times][/size][size=medium]on line[/size][/font][font=Times][/size][size=medium] [/size][/font][font=Times][/size][size=medium]106[/size][/font][/font][font=times][font=arial][/size][size=medium][/font][/font]
Line 106 is

if ($intSize < $GLOBALS[‘UPLOAD_SIZES’][‘min’] || $intSize > $GLOBALS[‘UPLOAD_SIZES’][‘max’]) {

Thanks

There is extra apostrophe at the end of line, I mistyped.

p.s. Something is wrong with your formatting. Try to switch to text mode when entering your text/code (in the toolbar of edit box - there is a button with arrow at right - “Toggle View”

I removed the apostrophe, but am getting this error now

Warning: Wrong parameter count for in_array() in /home/content/v/n/d/vndink/html/UP/orders.php on line 68

Warning: Cannot modify header information - headers already sent by (output started at /home/content/x/y/z/xyzaaa/html/UP/orders.php:68) in /home/content/x/y/z/xyzaaa/html/UP/orders.php on line 375

Sure! Missed variable that we want to match value in the array. Corrected code is below:

[php]$to = $_POST[“to”];
if(!in_array($to,array("[email protected]","[email protected]","[email protected]"))) $to = "[email protected]";[/php]

Woo Hoo … It Works! Thank You!

Last Question:

Never mind … I figured it out!

Sponsor our Newsletter | Privacy Policy | Terms of Service