我经常听到这样一个问题:“我有一个从网站发来的合同,我如何给通过表单发送的电子邮件增加一个附件呢?”
首先我要说的是要做到这个没有什么简单的办法。你要很好的理解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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software