Specifications

Sending and Reading Email
The main way to send mail in PHP is to use the simple mail() function. We discussed the use
of this function in Chapter 4, String Manipulation and Regular Expressions,so we wont
visit it again here. This function uses SMTP (Simple Mail Transfer Protocol) to send mail.
You can use a variety of freely available classes to add to the functionality of mail(). In
Chapter 27, Building a Mailing List Manager,we will use the HTML MIME mail class by
Richard Heyes to send HTML attachments with a piece of mail. SMTP is only for sending
mail. The IMAP (Internet Message Access Protocol, described in RFC2060) and POP (Post
Office Protocol, described in RFC1939 or STD0053) protocols are used to read mail from a
mail server. These protocols cannot send mail.
IMAP is used to read and manipulate mail messages stored on a server, and is more sophisti-
cated than POP which is generally used simply to download mail messages to a client and
delete them from the server.
PHP comes with an IMAP library. This can also be used to make POP and NNTP (Network
News Transfer Protocol) as well as IMAP connections.
We will look extensively at the use of the IMAP library in the project described in Chapter 26,
Building a Web-Based Email Service.
Using Other Web Services
One of the great things you can do with the Web is use, modify, and embed existing services
and information into your own pages. PHP makes this very easy. Lets look at an example to
illustrate this.
Imagine that the company you work for would like a stock quote for your company displayed
on its homepage. This information is available out there on some stock exchange site
somewherebut how do we get at it?
Start by finding an original source URL for the information. When you know this, every time
someone goes to your homepage, you can open a connection to that URL, retrieve the page,
and pull out the information you require.
As an example, weve put together a script that retrieves and reformats a stock quote from the
NASDAQ. For the purpose of the example, weve retrieved the current stock price of
Amazon.com. (The information you want to include on your page might differ, but the princi-
ples are the same.) This script is shown in Listing 17.1.
Using Network and Protocol Functions
C
HAPTER 17
17
USING NETWORK
AND
PROTOCOL
FUNCTIONS
371
22 7842 CH17 3/6/01 3:39 PM Page 371