2014-09-04 87 views
0

我想將兩個文件附加到一個電子郵件,但我不知道爲什麼我會遇到很多問題。我只需要附加更多的一個文件。該怎麼辦?帶郵件的多個文件附件()

下面的代碼:

$arquivo = isset($_FILES["fileCURR"]) ? $_FILES["fileCURR"] : FALSE; 

$fp = fopen($_FILES["fileCURR"]["tmp_name"],"rb"); 
$anexo = fread($fp,filesize($_FILES["fileCURR"]["tmp_name"])); 
$anexo = base64_encode($anexo); 

fclose($fp); 

$anexo = chunk_split($anexo); 

$boundary = "XYZ-" . date("dmYis") . "-ZYX"; 

$mens = "--$boundary" . $quebra_linha . ""; 
$mens .= "Content-Transfer-Encoding: 8bits" . $quebra_linha . ""; 
$mens .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $quebra_linha . "" . $quebra_linha . ""; //plain 
$mens .= "<strong>E-mail:</strong> $emailt <br> <strong>Website:</strong> $website" . $quebra_linha . ""; 
$mens .= "--$boundary" . $quebra_linha . ""; 
$mens .= "Content-Type: ".$arquivo["type"]."" . $quebra_linha . ""; 
$mens .= "Content-Disposition: attachment; filename=\"".$arquivo["name"]."\"" . $quebra_linha . ""; 
$mens .= "Content-Transfer-Encoding: base64" . $quebra_linha . "" . $quebra_linha . ""; 
$mens .= "$anexo" . $quebra_linha . ""; 
$mens .= "--$boundary--" . $quebra_linha . ""; 

$headers = "MIME-Version: 1.0" . $quebra_linha . ""; 
$headers .= "From: $email_from " . $quebra_linha . ""; 
$headers .= "Return-Path: $email_from " . $quebra_linha . ""; 
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"" . $quebra_linha . ""; 
$headers .= "$boundary" . $quebra_linha . ""; 

mail($email,$assunto,$mens,$headers, "-r".$email_from); 

echo"Success!"; 
+2

我會*高度*建議使用預先製作的電子郵件庫,而不是試圖自己構建它。 – 2014-09-04 19:54:22

+0

查看SwiftMailer,PHPMailer等。這幾乎不可能獨立完成。 – Brad 2014-09-04 19:54:45

回答

1

說實話,這將是方式更簡單和容易,如果你只需要添加的文件鏈接到郵件正文,因爲你已經上傳表單中的文件和存儲然後在你的服務器上,你可以在電子郵件正文中鏈接。