/*
print_r($_POST);
print "
";
print_r($_FILES);
print_r(error_reporting(E_ALL));
*/
$mode = $_POST["mode"];
//print "This is the mode-->". $mode;
$messagestring = "";
if ($mode == "send")
{
$result = validate();
//print "
$result";
//exit();
if ($result == "true")
{
$filetypes = array("text/plain","application/msword","application/pdf","application/vnd.ms-pki.stl","application/octet-stream"); //,"application/vnd.ms-pki.stl","application/octet-stream"
//print_r($filetypes);
//$filetypes = (["text/plain"],["application/msword"],["application/pdf"]);
$contactname = $_POST["contactname"]; //text input
$contactname = str_replace("\r\n", '',$contactname);
$email = $_POST["email"]; //text input
$email = str_replace("\r\n", '',$email);
$companyname = $_POST["companyname"]; //textarea
$companyname = str_replace("\r\n", '',$companyname);
$phonenumber = $_POST["phonenumber"]; //textarea
$phonenumber = str_replace("\r\n", '',$phonenumber);
$instructions = $_POST["instructions"]; //textarea
$instructions = str_replace("\r\n", '',$instructions);
$process = $_POST["process"];
if ($process != "")
{
if ($process == "fdm")
$process = "FDM Fused Deposition Modeling";
else if ($process == "fti")
$process = "FTI Film Transfer Imaging";
else if ($process == "srp")
$process = "SRP Subtractive Rapid Protyping";
}
$model = $_POST["model"];
if ($model != "")
{
if ($model == "solid")
$model = "Solid Normal";
else if ($model == "sparse")
$model = "Sparse";
}
$surface = $_POST["surface"];
if ($surface != "")
{
if ($surface == "unfinished")
$surface = "Unfinished";
else if ($surface == "basic")
$surface = "Basic Finish";
else if ($surface == "premium")
$surface = "Premium Finish";
}
$material = $_POST["material"];
if ($material != "")
{
if ($material == "White")
$material = "White";
else if ($material == "Black")
$material = "Black";
else if ($material == "Red")
$material = "Red";
else if ($material == "Blue")
$material = "Blue";
}
$message = "\n
Contact Name: $contactname \n
Email: $email \n
Company Name: $companyname \n
Phone Number: $phonenumber \n
RP Process: $process \n
Model Interior: $model \n
Surface Finish: $surface \n
Material Color: $material \n
Special Instructions: $instructions \n";
$subject = "Coho Design Quote Request";
$to = "khuber@cohodesignsllc.com";
$from = "khuber@cohodesignsllc.com";
// Obtain file upload vars
$headers = "From: $from";
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$bad_docs = "";
$fileatt_size = "";
$total_size = 0;
for ($count = 1; $count < 7; $count++)
{
$myFile{$count} = $_FILES['file'.$count]['tmp_name'];
if (is_uploaded_file($myFile{$count}))
{
$fileatt = $_FILES['file'.$count]['tmp_name'];
$fileatt_type = $_FILES['file'.$count]['type'];
$fileatt_name = $_FILES['file'.$count]['name'];
$fileatt_size = $_FILES['file'.$count]['size'];
$total_size = $total_size + $fileatt_size;
//print "
This is the total size--> ".$total_size;
//print "
MADE IT HERE";
// Read the file to be attached ('rb' = read binary)
if (in_array($fileatt_type, $filetypes))
{
if ($_FILES['file'.$count]['error'] != "1")
{
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
//print "MADE IT HERE
";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$files .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
else
{
$bad_docs .= $fileatt_name . " is too large. Please keep each file size below 2M.
";
}
}
else
{
$bad_docs .= $fileatt_name . " is not an accepted file type.
";
}
}
}
$endmessage .= "--{$mime_boundary}--\n";
if ($files != "")
{
$message .= $files . $endmessage;
//print "This is the entire message --> ". $message ."
";
$ok = mail($to, $subject, $message, $headers);
//print "
This is the mail message--> [".$message."]";
if ($ok == "")
{
if ($bad_docs == "")
{
$messagestring = "Thank you for sending your quote request!";
$_POST["contactname"] = "";
$_POST["companyname"] = "";
$_POST["email"] = "";
$_POST["phonenumber"] = "";
$_POST["instructions"] = "";
}
else
{
$messagestring = "Thank you for sending your quote request! But the files listed below were not sent.
". $bad_docs;
}
}
else
{
$messagestring = "Mail could not be sent. Sorry!
". $bad_docs;
mail("luke.helm@gmail.com", "Coho Design Quote Page Error", $message, $headers);
}
}
else
{
$messagestring = "Nothing was sent because of these files.
". $bad_docs;
}
}
else
{
$messagestring = $result;
}
}
?>