<?
// Sıra (sequence) numarasının kullanıldığı posta kutusu örneği
$user='anybody';
$pw  ='anybody';

function 
MessageSendForm($toaddress=""$subject=""$quote="") {
  global 
$PHP_SELF$SERVER_NAME$user;
  
  
$sender=$user.'@'.$SERVER_NAME;
  
?>
  <FORM ACTION="<?PHP echo $PHP_SELF.'?act=sended&sender='.$sender?>" METHOD="post">
    <H3>Mesaj Gönder</H3>
    Kimden:<?PHP echo $sender?><BR><BR>
    Kime:<BR>
    <INPUT TYPE="text" NAME="toaddress" VALUE="<?PHP echo $toaddress?>" SIZE="50"><BR><BR>
    Konu:<BR>
    <INPUT TYPE="text" NAME="subject"   VALUE="<?PHP echo $subject;   ?>" SIZE="50"><BR><BR>
    Mesaj:<BR>
    <TEXTAREA COLS="50" ROWS="10" NAME="body"><?PHP echo $quote?></TEXTAREA><BR><BR>
    <INPUT TYPE="submit" NAME="Submit" VALUE="Gönder">
  </FORM>    
<?

}

//---------------------------------------------------------- begin:  

  
$mailbox="{localhost/imap:143}INBOX";
  
$stream =imap_open($mailbox,$user,$pw);

  if(!isset(
$act)) $act="list";
  
  echo 
'Sıra (sequence) numarasının kullanıldığı durum:<BR>';

  switch(
$act) {
    case 
"list"  :
      
$header_array=imap_headers($stream);

      echo 
'<A HREF="'.$PHP_SELF.'?act=compose">Yeni Mesaj</A><BR><BR>';
      echo 
'<TABLE BORDER="1">';
      echo 
'<tr ALIGN="left">';
      echo 
'<th>Gönderen</th>';
      echo 
'<th>Kime</th>';
      echo 
'<th>Tarih</th>';
      echo 
'<th>Konu</th>';
      echo 
'</tr>';
      
      for(
$i=1$i<=count($header_array); $i++) { 

        
$header=imap_header($stream ,$i);

        echo 
'<tr>';
        echo 
'<td>'.$header->fromaddress.'</td>';
        echo 
'<td>'.$header->toaddress.'</td>';
        echo 
'<td>'.$header->Date.'</td>';
        echo 
'<td><a href="'.$PHP_SELF.'?act=view&seq='.$i.'">'.$header->Subject.'</a></td>';
        echo 
'</tr>';
      }
      echo 
'</TABLE>';
      break;
  
    case 
"view"   :
      if(empty(
$seq)) {
        echo 
"<BR>Hata...";
        exit;
      }
      
      
$header=imap_header($stream ,$seq);

      echo 
'<A HREF="'.$PHP_SELF.'?act=compose">Yeni Mesaj</A>';
      echo 
' --- ';
      echo 
'<A HREF="'.$PHP_SELF.'?act=reply&seq='.$seq.'">Mesajı Yanıtla</A><BR><BR>';

      echo 
'<HR ALIGN="left" WIDTH="300">';

      echo 
'<B>Gönderen:</B> '.$header->fromaddress.'<BR>'
      echo 
'<B>Kime:</B> '.    $header->toaddress  .'<BR>'
      echo 
'<B>Tarih:</B> '.   $header->Date       .'<BR>'
      echo 
'<B>Konu:</B> '.    $header->Subject

      echo 
'<HR ALIGN="left" WIDTH="300">';
      echo 
'<B>Mesaj:</B>';

      echo 
imap_body($stream,$seq);
      break;
    
    case 
"compose":
      
MessageSendForm($toaddress=""$subject=""$quote="");
      break;

    case 
"reply"  
      if(empty(
$seq)) {
        echo 
"<BR>Hata...";
        exit;
      }

      
$header=imap_header($stream ,$seq);

      
$quote="\n\n".
             
"--------------------------\n".
             
"From '$header->toaddress':\n".
             
imap_body($stream,$seq);
      
      
MessageSendForm($header->fromaddress"RE: ".$header->subject$quote);
      
      break;

    case 
"sended"  
      include(
"mail.php");
  }

?>