HomePHP Page 7 - Building A PHP-Based Mail Client (part 3)
When Things Go Wrong... - PHP
This third (and final) segment of our case study discusses theprocess of sending MIME-encoded email, demonstrating how to compose,forward and reply to email through a Web browser. It also discusses, indetail, the process of constructing a MIME-encoded message withattachments, explains PHP's HTTP upload capabilities, and examines thestandard error handler used throughout this case study.
The last script - an extremely simple one - is the error handler, "error.php". If you look at the source code, you'll notice many links to this script, each one passing it a cryptic error code via the $ec variable. Very simply, "error.php" intercepts the variable and converts it to a human-readable error message, which is then displayed to the user.
<?
// error.php - error handler
switch($ec)
{
// login failure
case 1:
$message = "An error occurred while logging you in. Please verify your
account information and <a href=logout.php>log in again</a>.";
break;
// session authentication failure
case 2:
$message = "An error occurred while performing your request. Please <a
href=logout.php>log in again</a>.";
break;
// POP3 connection problem
case 3:
$message = "A connection could not be opened to the mail server. Please
verify your account information and <a href=logout.php>log in again</a>.";
break;
// missing variable
case 4:
$message = "An error occurred while performing your request. Please <a
href=logout.php>log in again</a>.";
break;
// email addresses absent
case 6:
$message = "Your message could not be processed, as it contained no valid
recipient addresses. Please <a href=compose.php>try again</a>.";
break;
// attachment problem
case 7:
$message = "An error occurred while uploading the message attachment.
Please <a href=compose.php>try again</a>.";
break;
// email addresses invalid
case 8:
$message = "Your message could not be processed, as it contained one or
more invalid email addresses. Please <a href=compose.php>try again</a>.";
break;
// everything else
default:
$message = "An unspecified error occurred while performing your request.
Please <a href=logout.php>log in again</a>.";
break;
}
?>
<html>
<head>
</head>
<body bgcolor="White">
<?
// page header
?>
<font face="Verdana" size="-1">
<? echo $message; ?>
</font>
</body>
</html>
Here's what it looks like.
Simple and elegant - not to mention flexible. Found a new error? No problem - assign it an error code and let "error.php" know.