<?php
include("dbconnect.php");
function translate_object($obj){
return $obj->mailbox.'@'.$obj->host;
}
/* connect to server */
$hostname = '{10.2.1.248:995/pop3/ssl/novalidate-cert}INBOX';
$username = 'xxxxxx';
$password = 'xxxxxx';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to server: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
$headers = imap_headers($inbox);
$numEmails = sizeof($headers);
for($i = 1; $i < $numEmails+1; $i++)
{
$mailHeader = @imap_headerinfo($inbox, $i);
$from = $mailHeader->reply_toaddress;
$subject = strip_tags($mailHeader->subject);
$body = htmlentities(imap_body($inbox, $i));
$date = $mailHeader->date;
$rows = "SELECT * FROM requests";
$result = mysql_query($rows);
$num=mysql_numrows($result);
$query = "INSERT INTO requests (`date`, `from`, `subject`, `message`) VALUES ('".date("D d M H:i")."','$from', '$subject', '".mysql_real_escape_string($body)."')";
}
imap_delete($inbox,'1:*');
imap_expunge($inbox);
/* close the connection */
imap_close($inbox);
?>
|