只是为了好玩,我以为我会把它搞砸。最终变得比我想象的要复杂,因为我没有完全了解边界部分的工作原理,最终我发现起点和终点“-”很重要,然后就消失了。
<?php if(isset($_POST['submit'])) { //The form has been submitted, prep a nice thank you message $output = '<h1>Thanks for your file and message!</h1>'; //Set the form flag to no display (cheap way!) $flags = ''; //Deal with the email $to = 'me@example.com'; $subject = 'a file for you'; $message = strip_tags($_POST['message']); $attachment = chunk_split(base64_enpre(file_get_contents($_FILES['file']['tmp_name']))); $filename = $_FILES['file']['name']; $boundary =md5(date('r', time())); $headers = "From: webmaster@example.comrnReply-To: webmaster@example.com"; $headers .= "rnMIME-Version: 1.0rnContent-Type: multipart/mixed; boundary="_1_$boundary""; $message="This is a multi-part message in MIME format.--_1_$boundaryContent-Type: multipart/alternative; boundary="_2_$boundary"--_2_$boundaryContent-Type: text/plain; charset="iso-8859-1"Content-Transfer-Encoding: 7bit$message--_2_$boundary----_1_$boundaryContent-Type: application/octet-stream; name="$filename" Content-Transfer-Encoding: base64 Content-Disposition: attachment$attachment--_1_$boundary--"; mail($to, $subject, $message, $headers); }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>MailFile</title></head><body><?php echo $output; ?><form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" <?php echo $flags;?>><p><label for="message">Message</label> <textarea name="message" id="message" cols="20" rows="8"></textarea></p><p><label for="file">File</label> <input type="file" name="file" id="file"></p><p><input type="submit" name="submit" id="submit" value="send"></p></form></body></html>
真的很准,而且显然使用内联CSS隐藏表单有点便宜,您几乎可以肯定希望向用户提供更多反馈!此外,我可能会花更多的时间来确定文件的实际Content-Type,而不是欺骗和使用application / octet-stream,但是那部分还是很有趣的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)