Msgno; $to = $mailHeader->to; $from = $mailHeader->from; $subject = strip_tags($mailHeader->subject); $date = date("Y-m-d H:i:s", strtotime($mailHeader->date)); $size = $mailHeader->Size; foreach ($to as $id => $object) { $to_name = $object->personal; $to_email = $object->mailbox . "@" . $object->host; } foreach ($from as $id => $object) { $from_name = $object->personal; $from_email = $object->mailbox . "@" . $object->host; } unset($id); // Connect to the clients database $link = mysql_connect($mysql_host,$mysql_username,$mysql_password) or die('Could not connect to Client database'); mysql_select_db($mysql_database,$link) or die('Could not open client database'); // Create mySQL table if it doesn't exist if (!Table_Exists('email_stats_log')) { mysql_query($email_stats_table, $link); } // Check to see if this is already recoreded in the database $query = "SELECT id FROM email_stats_log WHERE to_email='$to_email' AND to_name='$to_name' AND from_name='$from_name' AND from_email='$from_email' AND subject='$subject' AND date='$date' AND size='$size'"; $result = mysql_query($query, $link) or die('Failed to get ID of page'); while ($record = mysql_fetch_array($result)) { $id=$record["id"]; } if(!$id) { $query = "INSERT INTO email_stats_log (to_email,to_name,from_name,from_email,subject,date,size) VALUES ('$to_email','$to_name','$from_name','$from_email','$subject','$date','$size')"; $result = mysql_query($query, $link) or die('Saving the page failed'); } } } imap_close($mbox); ?>