PHP
  Home arrow PHP arrow Page 2 - 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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 - Navigation and Headers


    (Page 2 of 4 )

    Next the navigation menu is created and the Inbox, Sent, Trash and Drafts page links are added, all of which will list the number of items contained within them:

      <tr>
              <td class="table"><a href="index.php?uid=<?=$_SESSION
    ['userid'];?>" class="menu">Inbox</a>(<? if(isset($numEmails)){
                              echo "($numEmails)";} ?>)</td>
            </tr>
            <tr>
              <td class="table"><a href="sent.php" class="menu">Sent
    (<? $query_sent = "select * from sent WHERE userid = '".$_SESSION
    ['userid']."'";
                $re = mysql_query($query_sent);
                $num = mysql_num_rows($re);
                if($num > 0){echo $num;}else{echo 0;}?>)</a></td>
            </tr>
            <tr class="table">
              <td class="menu"><a href="drafts.php"
    class="menu">Drafts(<? $query_msgs = "select * from drafts WHERE
    userid = '".$_SESSION['userid']."'";
                $res= mysql_query($query_msgs);
                $n = mysql_num_rows($res);
                if($n > 0){
                echo $n;}else{echo 0;}?>)</a></td>
            </tr>
            <tr>
              <td class="table"><a href="trash.php"
    class="menu">Trash(<? $query_trash = "select * from trash WHERE
    userid = '".$_SESSION['userid']."'";
                $result = mysql_query($query_trash);
                $num_trash = mysql_num_rows($result);
                if($num_trash > 0){
                echo $n_trash;}else{echo 0;}?>)</a></td>
            </tr>
          </table>

    Next, a table is created to display the column headers in which the message headers will be displayed. These headers are From, Subject, Date and Action:

                      <table width="100%" border="0" cellpadding="0"
    cellspacing="1" class="block">
            <tr class="table">
            <td width="7%" class="listtop">Status</td>
              <td width="22%" valign="top" class="listtop">From</td>
              <td width="38%" valign="top"
    class="listtop">Subject</td>
              <td width="22%" valign="top" class="listtop">Date</td>
              <td width="11%" valign="top"
    class="listtop">Action</td>
            </tr>

    The code below shows how the actual messages are downloaded from the mail server and inserted directly into the database:

    <? //if there are new msgs, get them
                if(isset($numEmails) &&($numEmails > 0)) {
                for($i = 1; $i < $numEmails+1; $i++)
    {
                $mailHeader = @imap_headerinfo($stream, $i);
                $from = $mailHeader->fromaddress;
                $subject = strip_tags($mailHeader->subject);
                $msgNo = imap_msgno( $stream, $i);
                $date = $mailHeader->date;
                list($dayName,$day,$month,$year,$time) = split("
    ",$date); 
                            $time = substr($time,0,5);
                $date = $day ."- ". $month ."- ". $year . " ". $time;
                $dates = $year ."- ". $month ."- ". $day;
    /*
    If you are going to implement attachment handling, this will be a
    good place to place your code. It will also be a good place to
    place your insert query code. See the attachments section below
    for a fuller explanation.
    */
    //put messages in db
                include "connect.php";
                $query = "INSERT INTO messages SET msg_num =
    '$msgNo', from = '$from',subject = '$subject',";
                $query .= "msg_body = '$msg_body', checked =
    '0',msg_date = '$dates', userid = '$user'";
                mysql_query($query);

    When the newly downloaded messages are inserted in to the database, the checked column in the messages table is set to zero(0). This makes it easy to differentiate between old and new messages. You can also use the date to differentiate between old and new messages.

    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

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT