将 HTML 作为电子邮件附件发送
我正在尝试发送一封带有 HTML 附件的电子邮件,
我不想在消息中显示 html,
我实际上想要附加该文件。
我已经完成一半了,我已在电子邮件中附加了文件,
但 hotmail 正在显示邮件中的 html 以及附件。
我使用 mime 类型:application/x-download 但也尝试过 text/html,两者都有相同的结果。
如果无法回答这个问题,如果有人知道可以在任何计算机上打开的文件类型(pdf 或图像除外),其中文件源可以包含原始/未压缩文本,这将很有用。我基本上是通过电子邮件发送一张凭证,并将用户详细信息填写到凭证上,因此我使用 str_replace
将它们放在那里,因此不能使用带有 str_replace
的 pdf代码>.
I'm trying to send an email with an HTML attachment,
I don't want the html to show in the message,
I actually want the file to be attached.
I'm half way there, I have the file attached in the email,
but hotmail is showing the html in the message aswell as attaching it.
I'm using the mime type: application/x-download but have also tried text/html, both have the same result.
Failing the answer to this question, it would be useful if someone knows a file type that can be opened on any computer (except pdf or images) where the source of the file can contain raw/uncompressed text. I'm basically emailing a voucher with the users details filled in onto the voucher, so I'm using str_replace
to get them on there and so can't use a pdf with str_replace
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将 content-disposition 设置为附件,则 MUA 不应显示 HTML,直到用户访问它。
If you set the content-disposition to attachment then the MUA should not display the HTML until the user accesses it.
如果您还没有,请不要直接使用 PHP
mail()
函数。使用包装类,例如 SwiftMailer 或 PHPMailer。它们为您提供更大的灵活性并且更安全。至于生成凭证,如果他们无法打印电子邮件,我最想用 GD 生成图像。这样所有用户都可以打开它。例如,有些人可能无法使用 PDF 阅读器。
是否有任何原因导致他们不能打印电子邮件作为凭证,或者您不能只给他们一个可以写下来的唯一凭证编号?这为他们提供了最大的灵活性,因为有些客户无法使用打印机。
If you are not already don't use PHPs
mail()
function directly. Use a wrapper class such as SwiftMailer or PHPMailer. They give you far more flexibility and are safer.As far as generating the voucher I would be most tempted to generate an image with GD if they aren't able to just print the email. This way it will be possible for all users to open it. Some people may not have access to a PDF reader for example.
Is there any reason why they can't just print out the email as the voucher or that you can't just give them a unique voucher number that the can write down? This gives them the greatest flexibility because some customers will not have access to a printer.
如果您使用 PHP 邮件功能,则必须手动编写整个电子邮件(标题、边界等),这很烦人并且难以调试。
如果您安装了 PEAR,则使用 Pear Mail Mime 可以非常轻松地完成此操作和 Pear Mail 扩展。它们使用起来非常简单。
如果您没有安装 PEAR,您可以使用其他包装器(Treffynnon 的帖子中提到)。
If you are using the PHP mail function, you will have to code the ENTIRE email by hand (headers, boundaries, ect) which is annoying and can be difficult to debug.
If you have PEAR installed, they make it extremely easy to do this with the Pear Mail Mime and Pear Mail extensions. They are very simple to use.
If you don't have PEAR installed, there are other wrappers you can use (mentioned in the post by Treffynnon).