作为初学者,我创建了这段代码
$o1 = $_POST['pliki'];
$o12 = $_POST['pliki2'];
$o2 = $_POST['o2'];
$o22 = $_POST['o22'];
$tab1 = explode(',', $o1);
$tab12 = explode(',', $o12);
$tab2 = explode(',', $o2);
$tab22 = explode(',', $o22);
if(isset($o2) && (bool) $o2) {
$format_wydruku1=$_POST['format_wydruku1'];
$format_wydruku2=$_POST['format_wydruku2'];
$to = "mail@mail.com";
$from = "mail@mail2.com";
$subject ='Zamówienie od '.$imie.' '.$nazwisko;
$message = "\n\n";
$tab111=array_merge($tab1, $tab12);
$tab222=array_merge($tab2, $tab22);
for($i = 0; $i<count($tab111); $i++) {
$plik2 = "../upload/";
$plik2 .= $tab222[$i];
$name2 = $tab111[$i];
if($i<count($tab1)){
$message .= $name2." ilosc kopii: ".$ile1." format wydruku:".$format_wydruku1."\n";
}else if($i>=count($tab1)){
$message .= $name2." ilosc kopii: ".$ile2." format wydruku:".$format_wydruku1."\n";
}
}
/////////////////////////////////////////////////////////////////////////
$headers = "From: $from";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//$headers .="Content-type: text/html; charset=utf-8";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\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";
$message .= "--{$mime_boundary}\n";
$FfilenameCount = 0;
for($i = 0; $i<count($tab111); $i++) {
if($i<count($tab1)){
$plik = "../upload/";
$plik .= $tab2[$i];
$afile = @fopen($plik,"rb");
if(empty($afile)){
continue;
}
$data[i] = @fread($afile,filesize($plik));
@fclose($afile);
$data[i] = chunk_split(base64_encode($data[i]));
$name = $tab111[$i];
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data[i] . "\n\n";
$message .= "--{$mime_boundary}\n";
}else if($i>=count($tab1)){
$plik = "../upload/";
$plik .= $tab222[$i];
$afile = @fopen($plik,"rb");
if(empty($afile)){
continue;
}
$data[i] = @fread($afile,filesize($plik));
@fclose($afile);
$data[i] = chunk_split(base64_encode($data[i]));
$name = $tab111[$i];
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data[i] . "\n\n";
$message .= "--{$mime_boundary}\n";
}
}
if(mail($to, $subject, $message, $headers)) {
echo '<p>Sent</p>';
} else {
echo "<p>error, try again!</p>";
}
}else{
通过一些额外的信息发送所选文件。它正在工作,但是......有时它会发送正确的文件,有时候不会......不知道如何修复它,以及问题究竟在哪里。所附的名字总是正确的......