带邮件的多个文件附件()

问题描述:

我想将两个文件附加到一个电子邮件,但我不知道为什么我会遇到很多问题。我只需要附加更多的一个文件。该怎么办?带邮件的多个文件附件()

下面的代码:

$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

说实话,这将是方式更简单和容易,如果你只需要添加的文件链接到邮件正文,因为你已经上传表单中的文件和存储然后在你的服务器上,你可以在电子邮件正文中链接。