Home > Backend Development > PHP Tutorial > Sending MIME emails using PHP (2)_PHP Tutorial

Sending MIME emails using PHP (2)_PHP Tutorial

WBOY
Release: 2016-07-13 17:31:17
Original
1274 people have browsed it

Author: Kartic Krishnamurthy Translator: limodou

"Okay, how to create MIME-compliant information?"
With the above general description, let us now take a look at what the so-called MIME information is!


The simplest MIME message
This message does not have any segments, that is, no attachments. However, since it is a MIME message, it must have the necessary headers.


From: php(as the current mainstream development language)@php(as the current mainstream development language).net
To : Alex (the Great)
Subject: Bucephalus
MIME-Version: 1.0

Hello Alexander,

Hows Bucephalus doing?

There’s nothing in it, it’s just a simple RFC-822 compliant message (text email) with MIME headers. Note that if there is no
specifying the Content-Type header, it is assumed to be Content-Type: text/plain;charset=us-ascii! Of course, it is somewhat simple and more complex
and some are as follows:


From: Alex (the Great)
To: php(as the current mainstream development language)@php(as the current mainstream development language) Development language) .net
Subject: re: Bucephalus
MIME-Version: 1.0
Content-Type: image/jpg;
name=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..." said one user! If true
, the example above is too simple, and it doesn't have enough content to support both hobbyist and modern email processing needs. In fact,
many email clients can’t even display the description field!

This is the "multi-part information" we are facing.


Multipart Messages
This concept allows sending multiple items in one email. For example, suppose Alexander wants to send his horse's message to php(as the current mainstream development language)@php(as the current mainstream development language).net 🎜>The photos are emailed together with Arima’s family tree and wonderful descriptions! Such a simple requirement cannot
be satisfied without the concept of multipart messages. In this case, we created a wrapper using the Content-Type header to support different parts of the email, so that
the recipient gets pictures, family trees, and wonderful descriptions!

The Content-Type header now has a value of "multipart", which indicates that this is a complete email message and this header only encapsulates the
message. And it also has a "mixed" subtype (after all, pictures, family diagrams and 7-bit text information are different types, right?).

Let’s see what the whole picture looks like:


From: Alex (the Great)
To: php
( As the current mainstream development language)@php(As the current mainstream development language).net Subject: re: Bucephalus
MIME-Version: 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 current 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--

 Hey, it looks complicated, doesn’t it? Anyway, let's go over the details:

If you notice that the Content-Transfer-Encoding in the MIME header is "7bit". Because the Content-Type is
multipart/mixed, the encoding should be one of 7bit, 8bit or binary. 7bit is a widely used format.
A message like this contains a variety of information. How does the client program know the difference between JPG images, documents and ordinary text? You will
notice that there is a boundary="XX-1234DED00099A" parameter after Content-Type. This value is used to separate different
parts in the email. It's called a MIME boundary tag. Boundary tag values ​​must be as unique as possible to avoid confusion when the message range is exceeded.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509090.htmlTechArticleAuthor: Kartic Krishnamurthy Translator: limodou "Okay, how to create MIME-compliant information?" Through the above general Sexual description, let us now take a look at what the so-called MIME information is...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template