这是我提出的解决方案。根据上传代码和附加文件信息花了一点时间。另外我遇到了标题的问题,但我设法让它工作,它运作良好。
if ((($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "
";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "
";
echo "Type: " . $_FILES["file"]["type"] . "
";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
echo "
File submitted.";
}
}
}
else
{
echo "Invalid file";
}
// DO THE MAILING HERE
$filename = "upload/" . $_FILES["file"]["name"];
;
$to3 =
$to4 =
$subject = 'Sustainability Photo Contest';
$bound_text = "dacc1231";
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n";
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: multipart/mixed; boundary=\"$bound_text\"". PHP_EOL;
$headers .= "From: noreply@dacc.edu\r\n";
$fields = array('name','address','city','state','zip','phone','photo','location');
$greet = "The following was submitted on " . date("F j, Y, g:i a") . "
";
$body = $greet;
//$cn = 1;
foreach($fields as $efield) {
if(isset($_POST[$efield])) {
if($efield == "name") {
$body.= "Name: " . $_POST[$efield] . "
";
} elseif($efield == "address") {
$body.= "Address: " . $_POST[$efield] . "
";
} elseif($efield == "city") {
$body.= "City: " . $_POST[$efield] . "
";
} elseif ($efield == "state") {
$body.= "State: " . $_POST[$efield] . "
";
} elseif ($efield == "phone") {
$body.= "Daytime Phone Number: " . $_POST[$efield] . "
";
} elseif ($efield == "photo") {
$body.= "Name of Photo: " . $_POST[$efield] . "
";
} elseif ($efield == "location") {
$body.= "Location where Photo was taken: " . $_POST[$efield] . "
";
}
}
}
$message = "If you can see this MIME than your client doesn't accept MIME types!\r\n"
.$bound;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."Here is a Submission for the Photo Contest\r\n" .$body ."\r\n"
.$bound;
$file = file_get_contents($filename);
$message .= "Content-Type: image/jpg; name=\"".$filename."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-disposition: attachment; file=\"".$filename."\"\r\n"
."\r\n"
.chunk_split(base64_encode($file))
.$bound_last;
if(mail($to3, $subject, $message, $headers)
&&
mail($to4, $subject, $message,$headers ))
{
echo '
MAIL SENT';
} else {
echo '
MAIL FAILED';
}
?>