3.2. Choosing POP3

You're probably asking yourself how to accept incoming messages and run the PHP scripts since you're now working in the realm of e-mail. There are no HTTP requests and you won't be receiving $_GET and $_POST variables from the user. Instead, the scripts will be scheduled to run automatically and emulate a person using an e-mail client to connect to a mail server and retrieve messages from the account's inbox.

Most people's exposure to the e-mail is limited to the mail client program they use, such as Thunderbird or Outlook. Few care about the path a message takes so long as it is received by the intended recipient. Behind the scenes, several different servers coordinate the delivery, and the "life" of an e-mail message can be quite exciting as it is passed along.

An e-mail message starts at the mail client, which sends it off to an SMTP (Simple Mail Transfer Protocol) server. The SMTP server is responsible for routing mail across the Internet to other mail servers. The final server in the chain delivers the message to the account's maildrop directory where it waits to be retrieved by the recipient. The recipient uses his or her mail client to connect to a POP3 (Post Office Protocol version 3) or IMAPv4 (Internet Message Access Protocol version 4) server, which in turn reads the maildrop and presents the message. This is shown in Figure 3-1.

Figure 3-1. Figure 3-1

There are different options available to you to retrieve e-mail with PHP:

  • Write a stand-alone ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.