Use PHP to send MIME mail (2)

Source: Internet
Author: User

Author: Kartic Krishnamurthy Translator: limodou

"Well, how do I create MIME-compliant information? "
Through the General description above, let's take a look at what the so-called MIME information is!


Simplest MIME Information
This information does not contain any segments, that is, there is no attachment. However, because it is a MIME message, it must have a necessary header.


From: php (as the mainstream development language) @ php (as the mainstream development language). net
To: Alex (the Great) <alex@greece.net>
Subject: Bucephalus
MIME-type: 1.0

Hello Alexander,

Hows Bucephalus doing?

Nothing here, it's just a simple RFC-822-compliant message (Text mail) with MIME headers ). NOTE: If no
If the Content-Type header is specified, it is assumed to be Content-Type: text/plain; charset = us-ascii! Of course, it is simple and complex.
Some of them are as follows:


From: Alex (the Great) <alex@greece.net>
To: php (as the mainstream development language) @ php (as the mainstream development language). net
Subject: re: Bucephalus
MIME-type: 1.0
Content-Type: image/jpg;
Name1_buce.jpg
Content-Transfer-Encoding: base64
Content-Description: Take a look at him yourself

<... Base64 encoded jpg image of Bucephalus...>

"Hi, but I want to send a Word document and a picture of my puppy in the same email ...! "One user said! If it is true
The above example is too simple, and it does not have enough content to support enthusiasts and modern mail processing needs. Actually,
Many mail client software cannot even display the description field!

This is what we are faced ".


Multipart Messages)
This concept allows multiple items to be sent in one email. For example, if Alexander wants to send a Trojan to php (as the mainstream development language) @ php (as the mainstream development language). net
The photo email is accompanied by a family map with horses and wonderful instructions! Such a simple requirement does not involve the concept of multiple messages.
Satisfied. In this case, we have created an encapsulation using the Content-Type information header to support different parts of the mail, so that
Recipients get pictures, family profiles, and highlights!

The Content-Type Header now has a "multipart" value, which indicates that this is a complete mail information and this header only encapsulates
Information. It also has a sub-type of "mixed" (after all, the family map and 7-bit text information are different types, right ?).

Let's take a look at the entire image:


From: Alex (the Great) <alex@greece.net>
To: php (as the mainstream development language) @ php (as the mainstream development language). net
Subject: re: Bucephalus
MIME-type: 1.0
Content-Type: multipart/mixed;
Boundary = "XX-1234DED00099A ";
Content-Transfer-Encoding: 7bit

This is a MIME Encoded Message

XX-1234DED00099A
Content-Type: text/plain; charset = us-ascii
Content-Transfer-Encoding: 7bit

Hi php (as the mainstream development language ),

Attached you will find my horse, Bucephalus, pedigree chart and photo.

Alex

XX-1234DED00099A
Content-Type: image/jpg;
Name = "buce.jpg ";
Content-Transfer-Encoding: base64
Content-Description: "A photo of Bucephalus"

<... Base64 encoded jpg image of Bucephalus...>

XX-1234DED00099A
Content-Type: application/octet-stream;
Name = "pedigree.doc"
Content-Transfer-Encoding: base64
Content-Description: "Pedigree Chart of the great horse"

<... Base64 encoded doc (pedigree.doc) of Bucephalus...>

-- XX-1234DED00099A --

Yo, it looks complicated, isn't it? In any case, let's view the details again:

If you notice the Content-Transfer-Encoding in the MIME header, it is "7bit ". Because Content-Type is
Multipart/mixed, which must be encoded in 7bit, 8bit, or binary format. 7bit is a widely used format.
A message like this contains multiple types of information. How does a client program know the difference between JPG images, documents, and common texts? You will
Note that there is a boundary = "XX-1234DED00099A" parameter behind Content-Type. This value is used to separate the differences in emails.
. It is called the MIME boundary mark. The value of the Boundary Tag must be as unique as possible to avoid confusion when the email range is exceeded.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.