繁体   English   中英

在PHP中使用MIME的电子邮件文件附件

[英]Email file attachments using MIME in PHP

我正在尝试使用PHP发送带有附件的电子邮件。 我已经按照http://webcheatsheet.com/PHP/send_email_text_html_attachment.php#attachment上的出色教程进行了以下更改:

--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: application/txt; name="<?php echo $_POST[log_file]?>"  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

原始脚本或我的修改脚本似乎都没有将任何文件附加到我的电子邮件中。 任何人都知道我在做什么错。

注意:我附加到表单的文件都是文本文件(各种文件扩展名,例如.log,.txt等)。


好的,我现在证明我认为此脚本的MIME编码部分无法正常工作。 我已经在上载目录中放置了一个文本文件,并将脚本更改为:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_SERVER['DOCUMENT_ROOT']. '/upload/test.txt' ?>" 
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

当查看收据上的电子邮件来源时,我在Content-Type下看到完整的路径和文档名称:text / plain; name =,但没有附件,无论编码还是其他形式。

有人知道我该如何工作吗?

我尝试了以下方法:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_FILES['file']['name']; ?>"
Content-Transfer-Encoding: base64  
Content-Disposition: attachment

有趣的是,这显示了电子邮件源中的文件名,但没有附件:

--PHP-mixed-<?php echo $random_hash; ?>   
Content-Type: text/plain; name="<?php echo $_FILES['file']['temp_name']; ?>"
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 

返回一个空文件名并且仍然没有附件,我只能假定在执行此操作时临时文件已被删除?

确定最终通过将临时文件移动到服务器上的另一个位置,然后对该文件进行编码来使此工作正常。

不知道为什么不保存就不能对临时文件进行编码,但是至少我现在能使它工作。

感谢所有花时间回答此问题的人,您对我有很大帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM