【发布时间】:2014-10-29 16:50:41
【问题描述】:
我正在尝试将两个文件附加到电子邮件中,但我不知道为什么会遇到很多问题。我只需要附加一个文件。怎么办?
代码如下:
$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!";
【问题讨论】:
-
我强烈建议使用预制的电子邮件库,而不是尝试自己构建它。
-
查看 SwiftMailer、PHPMailer 等。靠自己几乎不可能做到这一点。