An email message often has a couple of parts in it. I will not go into what they all are, but if there is more than one part, then there is a good chance that the message contains at least one attachment. Then all we have to do is download the attachment(s). To find an attachment in an email message, first determine the number of parts in the message. If the message contains more than one part, start to search for the attachment and then save it to file when you find it: <? There are two things that you should do if you choose to implement attachment handling in this application. First you need to create a table that will take the name of the attachment (in the form of a link), the messageID of the message tow which the attachment belongs, and finally the user id. You create a separate table for attachments because one message can have more than one attachment, otherwise you would just put the attachment name in the messages table. Second, you need to add the attachment code just before you insert the newly downloaded messages in the database. That is also the point at which you should insert the attachment data. delete.php - The delete page just removes a message from the database and the returns the user to the index page. To delete only the message that we want, we use the msg_id that is passed by the index page: <? view.php - The view page enables you to read the entire email message that is retrieved from the database. You are presented with a table that shows all the headers and the message body. You also have the opportunity to reply to the message. In addition, the page includes all the application folders and navigation that you get on the index page: First, a dynamic table is built to display the various message headers and body retrieved from the database: if($n){ A link is presented here that takes you to the reply page: <tr> When looking at the message headers on the index page, you will see a link that points you to the view page; that link includes a mid variable. The script below uses that variable to retrieve the full message from the database: <?php The actual message is retrieved here and the result of the query is held in the $n variable. This variable is used to create a dynamic table later on: $query = "select * from messages where msg_id = Once the message has been viewed, it will be classed as an old message, so we need to update the database to reflect this. The checked column in the messages table needs to be set to one, so that the next time you visit the index page it won't retrieve this message as a new message: //set checked flag to true Conclusion In this part we looked at the index page, which is at the heart of the application and from which you can view or delete individual messages. We also had a brief look at how to handle attachments in a message and how to integrate them into this application. The issue of attachments is avoided in most PHP email tutorials on the Internet, so I hope the code that I put together here will be helpful. The next article will look at the pages that are referenced by the navigation links.
blog comments powered by Disqus |
|
|
|
|
|
|
|