我使用以下脚本发送带邮件的附件。它发送邮件但附件文件为空。我已经完成了脚本,但似乎没有找到错误的来源。
腓:
$file_name = $_FILES['attachment']['name'];
$temp_name = $_FILES['attachment']['tmp_name'];
$file_type = $_FILES['attachment']['type'];
// get file extension
$base = basename($file_name);
$extension = substr($base, strlen($base)-4, strlen($base));
// allowed file types
$allowed_extensions = array(".doc", ".docx", ".pdf");
$from = $_POST['email'];
$to = "info@mywebsite.com";
$subject = "CV Upload";
$message = "My CV";
$file_name = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
$header = "From: ".$from."\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset-iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
答案 0 :(得分:2)
检查您的代码
$content = chunk_split(base64_encode(file_get_contents($file)));
技术上,$file
不存在。使用$file_name
$content = chunk_split(base64_encode(file_get_contents($file_name)));