PHP
  Home arrow PHP arrow Page 2 - Building the Index Page for a PHP Email Application
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Building the Index Page for a PHP Email Application
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek