I often hear the following question: I have a contract from my website. how can I add an attachment to an email sent through a form? First of all, it's easy to do this.
I often hear this question: "I have a contract from my website. how can I add an attachment to an email sent through a form ?"
The first thing I want to talk about is that there is no simple way to do this. You must have a good understanding of PHP or other server-side scripting languages. Of course, you also need an account that truly supports PHP websites. If this premise is met, you can use PHP to send emails with attachments after reading this chapter.
1. how does the attachment work?
If you have searched for the "attachment" function in the PHP manual, there may be no results (at least I haven't written this article yet ), later, you will spend a lot of time learning this knowledge.
You may want to put the attachment in the recipient's mailbox together with the email when you send an email with an attachment to someone (for example, if you send a PNG image file to him/her, his/her mailbox will contain a txt file (e-mail folder and a .png File (attachment ).
But this is not how it works. when you add an attachment, your email program converts the attachment into a plain text file and writes the content in your (actual email) insert the text block next to it. After you send all the items, the recipient's Mailbox contains only one plain text file-a file containing both attachments and actual email content.
The following is an example of an email with an attachment (an HTML file.
- 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 = "mongod983d6b89a"
- Subject: Here's the subject
- -- Mongod983d6b89a
- Content-type: text/plain; charset = iso-8859-1
- Content-transfer-encoding: 8bit
- This is the body of the email.
- -- Mongod983d6b89a
- Content-type: text/html; name‑attachment.html
- Content-disposition: inline; filename=attachment.html
- Content-transfer-encoding: 8bit
- This is the attached HTML file
- -- Mongod983d6b89a --
The first seven lines are the mail headers. it is worth noting that the Content-type header tells the Mail program that an email is composed of more than one part, emails without attachments only have one part: the message itself. Electronics with attachments usually consist of at least two parts: messages and attachments. In this way, an email with two attachments is composed of three parts: the message, the first attachment, and the second attachment.
Different parts of emails with attachments are separated by a line, which is defined in the Content-type header. Each new part of the email starts with two hyphens (--) and a line.