我刚刚让PHP的邮件功能在我的测试环境中正常工作。
我有一个输出许多字符串的 PHP 应用程序。将这些字符串转换为附件真是太好了(*.TXT
-文件)在电子邮件中,无需先将它们存储在磁盘上并重新读回。这在 PHP 中可能吗?
是的,这是可能的。您只需将您的电子邮件消息设为多部分消息 https://www.rfc-editor.org/rfc/rfc2046#section-5.1使用以下语法:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=random-boundary
This is the optional preamble of a multipart/mixed message.
--random-boundary
Content-Type: text/plain
This is the main message body.
--random-boundary
Content-Type: text/plain
Content-Disposition: attachment; filename=file.txt
This is the content of the attached file.
--random-boundary--
This is the optional epilogue of a multipart/mixed message.
然后可以像任何其他消息一样描述每个部分。但您可能应该使用一个可以为您完成此操作的库。
现在如果你正在使用PHP’s mail功能 http://php.net/mail,前两行是标题,其余行是该邮件消息的内容。边界应该是随机边界,以便该字符串具有的可能性--
在它前面出现在某一部分的内容中的可能性很小。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)