我有一个工作申请表,需要允许用户发送他们的简历副本以及其他一些基本细节。我不需要将文件保存在服务器上,只需通过电子邮件作为附件发送即可。
我遵循了一些不同的教程和指南,并提出了以下功能:
function mail_file ($email,$from,$subject,$body,$file){
$boundary = md5(rand());
$headers = array(
"MIME-Version: 1.0",
"From:{$from}",
"Content-Type: Multipart/mixed; boundary = {$boundary}"
);
$message = array(
"--{$boundary}",
"Content-Type: text/plain: charset = utf-8",
"Content-Transfer-Encoding: 7bit",
"",
chunk_split($body),
"--{$boundary}",
"Content-Type: {$file['type']}: name={$file['name']}",
"Content-Disposition: attachment; filename= {$file['name']}",
"Content-Transfer-Encoding: base64",
"",
chunk_split(base64_encode(file_get_contents($file['path']))),
"--{$boundary}--"
);
return mail ($email, $subject, implode("\r\n",$message),implode("\r\n",$headers));
}
它发送一封电子邮件 - 但它是空白的,并且有 2 个附件(noname.txt 和 noname)。
有人可以看看上面的内容,并指出我正确的方向吗?