【发布时间】:2014-06-08 05:50:51
【问题描述】:
我希望使用 html 表单发送 2 个附加到电子邮件的文件。邮件与 2 个文件一起发送,但我下载时看不到文件(大小:0 ko)。 你不能帮我吗?这是我的php文件的代码:
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= "Ceci est un mail avec 2 fichiers joints\r\n";
$msg .= "\r\n";
$file = $_FILES['icone']['name'];
$fp = fopen($file, "rb"); // le b c'est pour les windowsiens
$attachment = fread($fp, filesize($file));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: multipart/mixed; name=\"$file\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
$file = $_FILES['nom_fichier']['name'];
$fp = fopen($file, "rb");
$attachment = fread($fp, filesize($file));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: multipart/mixed; name=\"$file\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$file\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
$destinataire = "jeanb@hotmail.com";
$expediteur = $_POST['email'];
$reponse = $expediteur;
echo "Ce script envoie un mail avec 2 fichiers joints à $destinataire";
mail($destinataire,
"Email avec 2 fichiers joints (dont 1 inline)",
$msg,
"Reply-to: $reponse\r\nFrom: $destinataire\r\n".$header);
警告信息是:
警告:fopen(date horloge.txt) [function.fopen]: 未能打开 流:中没有这样的文件或目录 /home/public_html/mail_candidat.php 在第 34 行
警告:filesize() [function.filesize]: stat failed for date /home/public_html/mail_candidat.php 第 35 行中的 horloge.txt
警告:fread():提供的参数不是有效的流资源 /home/public_html/mail_candidat.php 第 35 行
警告:fclose():提供的参数不是有效的流资源 在 /home/public_html/mail_candidat.php 第 36 行
Ce script envoie un mail avec 2 fichiers Joint à jeanb@hotmail.com
【问题讨论】:
-
在你的问题中使用英语。 ich antworte ja auch nicht auf deutsch.
-
嗯,错误信息清楚地告诉您,您正在尝试打开并读取一个不存在的文件。您的路径指向没有文件。这很可能是这里的 path 问题。您的当前工作目录是什么?
-
我希望用户上传我在电子邮件中直接收到的文件。我没有“当前工作目录”……有可能吗?