Location: PHPKode > projects > Akasha > postmail.php
<?

if ($akashaID == $ID) {

	include ("includes/global.inc"); 	// Global Variables
	include ("includes/functions.inc"); 	// Global Functions
	include ("classes/mime_mail.inc");	// Mime mail

	$msgbody = ereg_replace("chr(10)","\n",$msgbody);

	$mail = new mime_mail;
	$mailadress = getUserMailAdress($ID);	
	$mail->from    = $mailadress;
	$mail->to      = $to;
	$mail->cc      = $cc;
	$mail->bcc     = $bcc;
	$slashsiz_subject = stripslashes($subject); //CUA
	$mail->subject = $slashsiz_subject;
	$slashsiz_body = stripslashes($msgbody); //CUA
	$mail->body    = $slashsiz_body;

  $handle=opendir($attach_dir);
  while ($file = readdir($handle)) {
		$idvar = strstr($file,$ID);
		if ($idvar) {
			$attachedfile = strstr($file,"######");
			$attach_name = substr($attachedfile,6);
			$tersname = strrev($attach_name);
			$dosya_isim = stristr($tersname,".");
			$lenisim = strlen($dosya_isim);
			$extension=trim(strtolower(substr($attach_name,$lenisim)));

			$dosyatipi="application/octet-stream";
			$mime=fopen("mime.types","r");
			while ( !feof($mime) ) {
				$mytype=fgets($mime,1000);
				$mimeparts=explode("	",$mytype);	
				$mimeuzanti = trim(strtolower($mimeparts[1]));
	
				if ($mimeuzanti == $extension) {
					$dosyatipi=$mimeparts[0];
				}
			}
			fclose($mime);

      $fd = fopen("$attach_dir$file", "r");
 	    $data = fread($fd, filesize("$attach_dir$file"));
   	  fclose($fd);

     	$mail->add_attachment($data, $attach_name, $dosyatipi);

		}
  }
  closedir($handle); 

	$mail->send();

	$user_id = findUserByHash($ID);
	$mbox_id = findGidenKutusu($user_id);
	$date = date('Y M d - H:i');


	$mailbox_id = $mbox_id;
	$maxmessage = $out_quota;
        $messagecount = findMboxMessageCount($mailbox_id);
	$messagecount = $messagecount + $count;
        $artikmesaj = $messagecount - $maxmessage;


        if ($artikmesaj > 0) {

                for ($m=0;$m<=$artikmesaj;$m++) {
                        $query = "select min(message_id) from tblMessages where mbox_id = $mailbox_id";
                        $result = mysql_db_query("$dbname",$query);
                        if($result) {
                                while ($r = mysql_fetch_array($result)) {
                                        $minmessage = $r["min(message_id)"];

                                        $query1 = "delete from tblMessages where user_id = $user_id and mbox_id = $mailbox_id and message_id = $minmessage";
                                        $result1 = mysql_db_query("$dbname",$query1);
                                }
                        }
                }  
        }

	$msgbody = addSlashes($msgbody);
	$query = "insert into tblMessages values(NULL,$mbox_id,$user_id,'$mailadress','$to','$cc','','$date','$subject','$msgbody')";
	$result = mysql_db_query("$dbname",$query);
	mysql_close();

  $handle=opendir($attach_dir);
  while ($file = readdir($handle)) {
		$idvar = strstr($file,$ID);
		if ($idvar) {
			$attachedfile = strstr($file,"######");
			$attach_name = substr($attachedfile,6);

      $fd = fopen("$attach_dir$file", "r");
 	    $attach = fread($fd, filesize("$attach_dir$file"));
			$attach = imap_binary($attach);
   	  fclose($fd);

			$dosyatipi="application/octet-stream";
			$mime=fopen("mime.types","r");
			while ( !feof($mime) ) {
				$mytype=fgets($mime,1000);
				$mimeparts=explode("	",$mytype);	
				$mimeuzanti = trim(strtolower($mimeparts[1]));
	
				if ($mimeuzanti == $extension) {
					$dosyatipi=$mimeparts[0];
				}
			}
			fclose($mime);

    	$query = "insert into tblAttachments values(NULL,$message_id,'$attach',$user_id,'$dosyatipi','$attach_name')";

    	$result = mysql_db_query("$dbname",$query);
    	if($result) {
    		while ($r = mysql_fetch_array($result)) {
    		}
    	}
    	mysql_close();

			unlink("$attach_dir$file");
		}
  }
  closedir($handle); 

	Header("Location: mailbox.php?ID=$ID&mbox_id=inbox");

} else {
		Header("Location: main.php?error_code=1");
}
?>
Return current item: Akasha