0
礦山腳本不會發送附件(這是爲更多的人,但單一給出同樣的問題)。PHP - 郵件不會發送附件,只有沒有它附件
有代碼:
if ($_POST) {
$to = mysql_real_escape_string($_POST['to']);
$subject = mysql_real_escape_string($_POST['subject']);
$message = mysql_real_escape_string($_POST['message']);
if (empty($to) || empty($subject) || empty($message)) {
header("location: nation.php?error=empty");
} else {
$email = $b['email'];
$my_file = $_FILES['my_file']['tmp_name'];
$my_file_type = $_FILES['my_file']['type'];
$my_file_name = $_FILES['my_file']['name'];
$body = "";
//upload
if (is_uploaded_file($my_file))
{
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= 'From: <'.$email.'>' . "\r\n";
$headers .= "Content-Type: multipart/mixed;\n";
// Apro e leggo il file my_file
$file = fopen($my_file,'rb');
$data = fread($file, filesize($my_file));
fclose($file);
// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));
// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'my_file
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Aggiungo le intestazioni necessarie per l'my_file
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
// Definisco il tipo di messaggio (MIME/multi-part)
$body .= "This is a multi-part message in MIME format.\n\n";
// Metto il separatore
$body .= "--{$mime_boundary}\n";
// Questa è la parte "testuale" del messaggio
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n\n";
$body .= $message . "\n\n";
// Metto il separatore
$body .= "--{$mime_boundary}\n";
// Aggiungo l'my_file al messaggio
$body .= "Content-Disposition: attachment; filename=\"{$my_file_name}\"\n";
$body .= "Content-Transfer-Encoding: base64\n\n";
$body .= $data . "\n\n";
// chiudo con il separatore
$body .= "--{$mime_boundary}--\n";
if ($privilegi == '1') {
$nap = mysql_query("SELECT * FROM leads WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$body,$headers);
}
} else if ($privilegi == '2') {
$nap = mysql_query("SELECT * FROM contacts WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$body,$headers);
}
} else if ($privilegi == '3') {
$nap = mysql_query("SELECT * FROM agent WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$body,$headers);
}
} else {
$name = 'error';
}
} else {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if ($privilegi == '1') {
$nap = mysql_query("SELECT * FROM leads WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$message,$headers);
}
} else if ($privilegi == '2') {
$nap = mysql_query("SELECT * FROM contacts WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$message,$headers);
}
} else if ($privilegi == '3') {
$nap = mysql_query("SELECT * FROM agent WHERE country ='$to' AND staff='$username'");
while($abc = mysql_fetch_array($nap)) {
$em = $abc['email'];
$a = mail($em,$subject,$message,$headers);
}
} else {
$name = 'error';
}
就職於5/6分鐘......對不起,糟糕的代碼,我'不是專家:\ 它發送電子郵件沒有依附,我好睏惑,問題在哪裏?