This question already has an answer here:
This is the php code I'm using for my form (multiple files upload):
<?php
$to = "emailaddress@gmail.com";
$subject= "Request For Quote";
$todayis = date("l, F j, Y, g:i a") ;
$subject= "Request For Quote";
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$cmname = $_POST['cmname'];
$message = "
Date ------- $todayis
Name ------ $name
Last Name ------- $lastname
Email ----------- $email
Company --------- $cmname
";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $email\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$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";
foreach($_FILES as $userfile)
{
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name))
{
if(is_uploaded_file($tmp_name))
{
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
$message.="--{$mime_boundary}--\n";
if (mail($to, $subject, $message, $headers))
echo "Mail sent successfully.";
else
echo "Error in mail";
?>
Now I'd like to add a multiple select option box, like this:
<select data-placeholder="Select Multiple Items" class="chosen-select" multiple>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
</select>
That clearly doesn't upload the selected options, so I tried this:
<option name="option" type="text" id="option">Item 1</option>
adding this:
$option= $_POST['option'];
but it doesn't work. Can anyone help me out here, please, adding the multiple select to the php code. Thanks!
you need to add a name attribute to the select element if you want php to read it. Also ensure that it's enclosed inside a form.
eg.
by adding in brackets to the name attribute, the request var becomes an array allowing you to pass multiple values.