这是我用于表单的PHP代码(多个文件上传):
<?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";
?>
现在我想添加一个多选选项框,如下所示:
<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>
显然没有上传所选的选项,所以我尝试了这个:
<option name="option" type="text" id="option">Item 1</option>
添加:
$option= $_POST['option'];
但它不起作用。 任何人都可以帮助我在这里,请添加多个选择到PHP代码。 谢谢!
答案 0 :(得分:0)
如果你想让php读取它,你需要为select元素添加一个name属性。还要确保它包含在表单中。
例如
<select name="option[]" 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>
通过在name属性中添加括号,请求var成为一个允许您传递多个值的数组。