PHP
  Home arrow PHP arrow Building the Index Page for a PHP Emai...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building the Index Page for a PHP Email Application
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2006-11-08

    Table of Contents:
  • Building the Index Page for a PHP Email Application
  • Navigation and Headers
  • Retrieving Messages
  • Attachments

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building the Index Page for a PHP Email Application


    (Page 1 of 4 )

    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.

    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:

    <?php
    session_start();
    include("connect.php");
    //get popserver login credentials
    $query_details = "SELECT * FROM user WHERE user_id = '".$_SESSION
    ['userid']."'";
    $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;
    }
    }else{
    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,
    $userpassword)){
                $streamerror = "Connection to server failed";
    }
                if(!$headers = @imap_headers($stream)){
                $header = "No!";
                }else{
                $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>
      </tr>
    </table>
    <!-- InstanceEndEditable --></td>
      </tr>
      <tr>
        <td width="11%" valign="top"><!-- InstanceBeginEditable
    name="EditRegion4" -->
          <table width="100%" border="0" cellpadding="2"
    cellspacing="1" class="block">
            <tr>
              <td class="table"><strong>Folders:</strong></td>
            </tr>

    More PHP Articles
    More By Leidago


       · Hello,read this article in a hurry and got more hunger.We'd like to get more...
       · Hiya, just read this article - looks good and am going to give it a go. Just...
       · I will upload update source code for this up soon. All your questions will be...
     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway