开发大刘 潜水
  • 3发帖数
  • 3主题数
  • 0关注数
  • 0粉丝
开启左侧

回顾使用PHP原生发送电子邮件(终)文件附件

[复制链接]
开发大刘 发表于 2021-8-15 01:19:00 来自手机 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
File Attachments
文件附件
File attachments work just like mixed email, except that a different content type is used for the message as a whole (multipart/mixed instead of multipart/alternative), and there’s a new Content-Disposition header that tells the email client how to handle each part of the message.
文件附件的工作原理与混合电子邮件类似,不同的是,邮件作为一个团体利用不同的内容范例(多部分/混合而不是多部分/替换),而且有一个新的内容处理头,告诉电子邮件客户端怎样处理邮件的每个部分。
Let’s write a PHP script that processes a form submission that contains an email message to be sent, possibly with a file attachment, and sends it out. I’ll talk you through it line by line so that by the end you’ll not only have a useful snippet of PHP code, but also an understanding of how file attachments work. You can download the script (and the form for it) if you want to try it out for yourself.
让我们编写一个PHP脚本来处理表单提交,表单提交包含要发送的电子邮件(可能带有文件附件),并将其发送出去。我将一行一行地告诉您,如许到最后,您不仅可以获得有用的PHP代码片段,还可以了解文件附件是怎样工作的。如果您想亲自实验,可以下载脚本(及其表单)。
First, we grab the submitted values and place them in PHP variables. Most people have their servers set up to create global variables for submitted values automatically, but as of PHP 4.1 this is no longer the default, so we do it by hand just in case. Since we want to accept file attachments, it’s safe to assume that the form will be submitted with a POST request:
首先,我们获取提交的值并将它们放入PHP变量中。大多数人的服务器设置为自动为提交的值创建全局变量,但从PHP4.1开始,这不再是默认值,所以我们手工利用以防万一。由于我们希望接受文件附件,因此可以安全地假设表单将随POST请求一起提交:
And that’s how we send emails with file attachments in PHP!
这就是我们用PHP发送带有文件附件的电子邮件的方式!
Summary
总结
In this article, you probably learned a lot more about email than you ever wanted to know. That intimate knowledge about what makes email tick allowed us to do some pretty special things with PHP’s deceptively simple mail function.
在这篇文章中,你可能学到了比你想知道的更多的关于电子邮件的知识。通过对电子邮件产生原因的深入了解,我们可以利用PHP看似简单的邮件功能做一些非常特别的事变。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

猜你喜欢
在线客服邮箱
wxcy#wkgb.net

邮箱地址#换为@

Powered by 创意电子 ©2018-现在 专注资源实战分享源码下载站联盟商城