我经常听到这样一个问题:“我有一个从网站发来的合同,我如何给通过表单发送的电子邮件增加一个附件呢?”
首先我要说的是要做到这个没有什么简单的办法。你要很好的理解PHP或其它的服务器端的脚本语言。当然你还要一个真正支持PHP的网站的账号。如果满足了这个前提,在你读完了本章后就可以用PHP发送带附件的电子邮件了。
1.附件是如何工作的
如果你曾经在PHP的手册中搜索过“附件”函数,那么结果可能是什么都没有(至少在我写本文的时间还没有),后来你就要花很多时间来了解这方面的知识。
你也许会想当你给某个人发送一封带附件的电子邮件时,附件是和邮件一起放到收件人的信箱里的(比如,如果你给他/她发了一个PNG的图片文件,他/她的信箱里会包含一个txt文件(电子邮件)和一个.png文件(附件).
但这不是它的工作原理,当你加入一个附件时,你的邮件程序把附件转换成纯文本文件,并在你写的内容(实际的电子邮件)后面插入这个文本块。这个,当你把所有的东西发出来后,收件人的信箱里只有一个纯文本文件——一个同时包含附件和实际电子邮件内容的文件。
下面是一个带附件(一个HTML文件)电子邮件的例子。
Return-Path: Date: Mon, 22 May 2000 19:17:29 +0000 From: Someone To: Person Message-id: <83729KI93LI9214@example.com> Content-type: multipart/mixed; boundary="396d983d6b89a" Subject: Here's the subject --396d983d6b89a Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 8bit This is the body of the email. --396d983d6b89a Content-type: text/html; name=attachment.html Content-disposition: inline; filename=attachment.html Content-transfer-encoding: 8bit This is the attached HTML file --396d983d6b89a--
前面的7行是邮件的头,其中值得注意的是Content-type头部分,这个头告诉邮件程序电子邮件是由一个以上的部分组成的,不含附件的邮件只有一个部分:消息本身。带附件的电子通常至少由两部分组成:消息和附件。这样,带两个附件的邮件由三部分组成:消息,第一个附件和第二个附件。
带附件的电子邮件的不同部分之间用分界线来分隔,分界线在Content--type头中定义。邮件的每个新部分以两个连字号(--)和分界线开始。
本文链接:
收藏随意^^请保留教程地址.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
