Use PHP to collect POP3 mails (1)

Source: Internet
Author: User
This article briefly describes the principles of receiving and MIME mail through POP3 protocol. It provides two Practical php classes for receiving and MIME decoding, A sample is provided. It is divided into two parts: email receiving and MIME decoding. Here we will first introduce you to the receipt of emails. the decoding section will be described in detail in future articles, so stay tuned. At present, the largest application on the Internet should be non-Email. we are used to introducing the POP protocol every day.

This article briefly describes the principles of receiving and MIME mail through POP3 protocol, provides two Practical php classes for receiving and MIME decoding, and provides samples for use. It is divided into two parts: email receiving and MIME decoding. Here we will first introduce you to the receipt of emails. the decoding section will be described in detail in future articles, so stay tuned.

Currently, the largest application on the Internet should be non-Email. every day, we are used to communicating via Email every day. almost all major websites have launched their own WEB-based free Email system. In this article, I will introduce some principles of Email implementation. At the same time, we assume that you have a certain foundation for PHP programming and a certain understanding of the TCP/IP protocol.

POP protocol introduction
POP stands for Post Office PRotoco, which is the Post Office Protocol used for email reception. it is now commonly used in the third edition, POP3 for short. Through the POP protocol, after the client logs on to the server, it can delete its own emails, or download it to the local device. after the download, the email client software can modify and delete emails locally. The IMAP protocol is also used to receive emails, which is growing rapidly. we will not discuss this in this article.

POP servers generally use port 110 of TCP. if Foxmail is used, you can see the following command in the prompt window:

"Connecting to 62.123.23.123: 110 ";

"USER BOSS_CH ";

"PASS ..............";

Let's take a look at the transcript of a conversation with the POP3 server:

Telenet pop.china.com110

+ OK AIMC POP service (mail2.china.com) is ready.

USER boss_ch

+ OK Please enter passWord for user .

PASS ******

+ OK boss_ch has 1 messages (750 octets)

STAT

+ OK 1 750

LIST

+ OK 1 messages (750 octets)

1 750

RETR 1

+ OK 750 octets

Received: from smtp2.ptt.js.cn ([202.102.24.37]) by china.com (JetMail 2.5.3.0)

With SMTP id jm4839cc4227; Sat, 23 Sep 2000 05:31:21-0000

Received: from chenjunqing ([61.155.120.6]) by smtp2.ptt.js.cn

(Netscape Messaging Server 4.15) with SMTP id G1BRHJ03. V07

; Sat, 23 Sep 2000 13:34:31 + 0800

Date: Sat, 23 Sep 2000 13:34:18 + 0800

From: =? ISO-8859-1? Q? = B3 = C2 = BF = A1 = C7 = E5? =

To: boss_ch@china.com

Subject: =? ISO-8859-1? Q? = D3 = CA = BC = FE = CA = BE = C0 = FD? =

X-mailer: FoxMail 3.1 [cn]

Mime-type: 1.0

Content-Type: text/plain; charset = "GB2312"

Content-Transfer-Encoding: 8bit

Message-ID:

Hello!

This is a small example of an email.

QUIT

+ OK Pop server Signing off.

The following is a brief introduction to several frequently-used POP3 commands:

Command parameter status description

------------------------------------------

USER username recognizes that if this command is successful with the following pass command, status conversion will occur.

PASS password approval

APOP Name, Digest recognizes that Digest is the md5 Message Digest

------------------------------------------

STAT None processes the mailbox statistics sent back by the request server, such as the total number of emails and total bytes.

UIDL [Msg #] indicates the unique identifier of the response message. Each identifier of a POP3 session will be unique.

LIST [Msg #] number of returned mails processed and size of each email

RETR [Msg #] process and return all text of the email identified by parameters

DELE [Msg #] The processing server marks the emails marked by parameters as deleted and is executed by the quit command.

RSET None processing server resets all emails marked as deleted, used to cancel the DELE command

TOP [Msg #] The processing server will return the content of the first n lines of emails identified by parameters. n must be a positive integer.

The NOOP None processing server returns a positive response without any operation.

------------------------------------------

QUIT None update exit

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.