【问题标题】:Multiple file attachments with mail()使用 mail() 的多个文件附件
【发布时间】: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 等。靠自己几乎不可能做到这一点。

标签: php file email send


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-09-29
    • 1970-01-01
    • 2017-10-12
    • 2012-02-16
    • 2017-08-08
    • 2013-04-13
    相关资源
    最近更新 更多