13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

654 Chapter 29 Building a <strong>Web</strong>-Based Email Service<br />

Solution Overview<br />

The general flow through this web-based system isn’t much different from other email<br />

clients. Figure 29.1 shows a diagram illustrating the system flow <strong>and</strong> modules.<br />

Login<br />

Set up<br />

account<br />

Select<br />

Account<br />

View<br />

mailbox<br />

New<br />

mail<br />

Logout<br />

View<br />

message<br />

Reply<br />

Reply<br />

all<br />

Forward<br />

Delete<br />

Show/hide<br />

headers<br />

Figure 29.1<br />

The interface for Warm Mail gives the user mailbox-level functionality<br />

<strong>and</strong> message-level functionality.<br />

As you can see, you first require a user to log in <strong>and</strong> then give him a choice of options.<br />

He can set up a new mail account or select one of his existing accounts for use. He also<br />

can view his incoming mail—responding to, forwarding, or deleting it—<strong>and</strong> send new<br />

mail.<br />

You also give the user the option of viewing detailed headers for a particular message.<br />

Viewing the complete headers can tell you a lot about a message.You can see which<br />

machine the mail came from—a useful tool for tracking down spam.You can see which<br />

machine forwarded it <strong>and</strong> at what time it reached each host—useful for assigning blame<br />

for delayed messages.You might also be able to see which email client the sender used if<br />

the application adds optional information to the headers.<br />

This project uses a slightly different application architecture. Instead of having a set of<br />

scripts, one for each module, this project has a slightly longer script, index.php, that<br />

works like the event loop of a GUI-driven program. Each action taken on the site by<br />

clicking a button brings you back to index.php, but with a different parameter.<br />

Depending on the parameter, different functions are called to show the appropriate output<br />

to the user.The functions are in function libraries, as usual.<br />

This architecture is suitable for small applications such as this. It suits applications that<br />

are very event driven, where user actions trigger functionality. Using a single event h<strong>and</strong>ler<br />

is not suitable for larger architectures or projects being worked on by a team.<br />

A summary of the files in the Warm Mail project is shown in Table 29.1.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!