Building A PHP-Based Mail Client (part 3) - Composing Yourself (
Page 2 of 8 )
You'll remember, from our discussion of the "view.php" script, that the
generated page includes a series of command buttons at the top.
<!-- command buttons from view.php -->
<!-- some HTML snipped out for readability -->
<td><a href="compose.php">Compose</a></td>
<td><a href="reply.php?id=<? echo $id; ?>">Reply</a></td>
<td><a href="forward.php?id=<? echo $id; ?>">Forward</a></td>
<td><a href="delete.php?dmsg[]=<? echo $id; ?>">Delete</a></td>
<td><a href="list.php">Messages</a></td>
The first (and simplest) of these is the "compose.php"
script, which merely creates a blank form representing a new email message.
<?
// compose.php - compose new message
// includes and session check
?>
<html>
<head>
</head>
<body bgcolor="White">
<?
// page header
?>
<!-- commands - snipped -->
<table border="0" cellspacing="1" cellpadding="5" width="100%">
<form action="send.php" method="post" enctype="multipart/form-data">
<tr>
<td valign=top><font face="Verdana" size="-1"><b>From: </b></font></td>
<td valign=top width=100%><input type="Text" name="from" size="30"
maxlength="75" value="<? echo $SESSION_USER_NAME . "@" .
$SESSION_MAIL_HOST; ?>">
</td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>To: </b></font></td>
<td valign=top><input type="Text" name="to" size="30"></td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>Cc: </b></font></td>
<td valign=top><input type="Text" name="cc" size="30"></td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>Bcc: </b></font></td>
<td valign=top><input type="Text" name="bcc" size="30"></td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>Subject: </b></font></td>
<td valign=top><input type="Text" name="subject" size="50"></td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>Message: </b></font></td>
<td valign=top bgcolor="White"><textarea name="body" cols="60" rows="15"
wrap="VIRTUAL" ></textarea></td>
</tr>
<tr>
<td valign=top><font face="Verdana" size="-1"><b>Attachment:
</b></font></td>
<td valign=top bgcolor="White"><input type="file" name="attachment"
size="20"></td>
</tr>
</form>
</table>
</body>
</html>
Here's what it looks like:

There are a couple of things to be noted here. First,
the
<input type="file" name="attachment" size="20">
construct near the end of the form. This form construct
creates a "Browse..." button on the form, which allows for file selection and
upload through the browser; I plan to allow the user to upload message
attachments though this construct.
Second, note the form encoding type
and method:
<form action="send.php" method="post" enctype="multipart/form-data">
<!-- snipped out HTML -->
</form>
This encoding type and method must be specified whenever you
attempt file upload over HTTP. PHP's official site has a manual page devoted to
the topic - take a look at
http://download.php.net/manual/en/features.file-upload.php and then come back
for more.