Home arrow PHP arrow Building the Index Page for a PHP Email Application

Building the Index Page for a PHP Email Application

In this third part of a four-part article series on building a PHP email application, we will look at the index page. This page is the heart of the application. We will also look at how to handle attachments in a message and how to integrate them into this application.

  1. Building the Index Page for a PHP Email Application
  2. Navigation and Headers
  3. Retrieving Messages
  4. Attachments
By: Leidago
Rating: starstarstarstarstar / 8
November 08, 2006

print this article



The login system that we created in the previous article sends the user through to the index page. This page then downloads the messages from the server and displays its headers. The login script also sends the user ID, which is stored in a session variable called $_SESSION['userid']. In this article we will discuss the work done by the index page as well as the pages to which it links. We will also take a brief look at attachments.

Below is a screen shot of the index page:

Index page

The index page displays the newly downloaded messages in a table with five columns. These columns list (among other things) the date, subject and from field of the messages. There are three things that happen in this script. First the mail connection details of the logged-in user are retrieved:

//get popserver login credentials
$query_details = "SELECT * FROM user WHERE user_id = '".$_SESSION
$result_details = mysql_query($query_details);
$num_details = mysql_num_rows($result_details);
if($num_details > 0 ){
while($res = mysql_fetch_array($result_details)){
$pop = $res['pop3'];
$usname = $res['remuser'];
$pw = $res['rempass'];
$email = $res['email'];
$user = $res['user_id'];
global $email;
echo mysql_error();

Then based on the user details, the code moves on to make the connection to the mail server and stores the number of retrieved mail messages in the $numEmails variable:

if($num_details >0){
//put popserver details in headers array
            $mbox = "{".$pop.":110/pop3}INBOX";
            $userid = "$usname";
            $userpassword = "$pw";
            if(!$stream = imap_open($mbox, $userid,
            $streamerror = "Connection to server failed";
            if(!$headers = @imap_headers($stream)){
            $header = "No!";
            $numEmails = sizeof($headers);

Next, the table is created and the menu and navigation panels are displayed. The navigation panel contains links to the Calendar, Contacts and profile pages. I also attached the user_id variable, which will be used to retrieve the items specific to the user in each of the above folders to the links. When a user clicks on any of these links, they will be taken to the appropriate page:

<table width="100%" border="0" cellspacing="1" class="block">
  <tr class="table">
    <td width="15%" class="table"><a href="NewMsg.php?uid=<?
=$_SESSION['userid'];?>" class="menu">New Message </a></td>
    <td width="15%"><a href="contacts.php?uid=<?=$_SESSION
['userid'];?>" class="menu">Contacts</a></td>
    <td width="12%"><a href="showcal.php?uid=<?=$_SESSION
['userid'];?>" class="menu">Calendar</a></td>
    <td width="46%"><a href="profile.php?uid=<?=$_SESSION
['userid'];?>" class="menu">Profile </a></td>
    <td width="4%">&nbsp;</td>
    <td width="4%">&nbsp;</td>
    <td width="4%">&nbsp;</td>
<!-- InstanceEndEditable --></td>
    <td width="11%" valign="top"><!-- InstanceBeginEditable
name="EditRegion4" -->
      <table width="100%" border="0" cellpadding="2"
cellspacing="1" class="block">
          <td class="table"><strong>Folders:</strong></td>

>>> More PHP Articles          >>> More By Leidago

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: