栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

简单的PHP形式:电子邮件附件(代码高尔夫)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

简单的PHP形式:电子邮件附件(代码高尔夫)

只是为了好玩,我以为我会把它搞砸。最终变得比我想象的要复杂,因为我没有完全了解边界部分的工作原理,最终我发现起点和终点“-”很重要,然后就消失了。

<?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,但是那部分还是很有趣的。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/615408.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号