HomePHP Page 3 - Building A PHP-Based Mail Client (part 3)
Return To Sender - 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.
Next up, "reply.php", which receives a message ID from "view.php"; it uses this message ID to determine which message has been selected for replying. Stripped to its essence, this is an HTML form similar to the one you just saw, with some additional code to format the message and its headers appropriately.
This is a little more complicated than "compose.php", since I
need to first retrieve the original message from the mail server and then pre-fill the form with values sourced from that message. For example, I need to fill the To: field with the email address of the message's original sender (or the contents of the Reply-To: header, if it exists),
<?
// check for Reply-To: header and use if available
if($headers->reply_toaddress)
{
$to = trim($headers->reply_toaddress);
}
else
{
$to = trim($headers->fromaddress);
}
?>
insert the subject line from the original message with a "Re:
" prefix (if one doesn't already exist),
Here, too, I need to run the parse() function to look for
attachments, and only display text attachments within the message body (this code snippet was previously explained in the second segment of this article).
Finally, since users should have the ability to add
attachments to a reply, the form also includes a "file" input type and a "multipart/form-data" form encoding type.
<form action="send.php" method="POST" enctype="multipart/form-data">
<!-- snipped out HTML -->
<input type="file" name="attachment" size="20">
<!-- snipped out HTML -->
</form>