I know of two ways to approach this problem. One is to use PHP's IMAP functions to open a mailbox and reply to unread emails. The problem with the approach is that you would have to set up a crontab for the script. The second approach would be to intercept the email. The problem with this approach is that it requires some additional setup.
Here is a guide on intercepting email: http://tinsology.net/2009/01/interce...mail-with-php/
If you choose the imap path you'll need to decide what you want to do with the emails once you've replied to them. If you want to delete them, just use imap_delete once you've replied to it. If you need to keep it you can use the 'answered' flag to make sure you won't reply to the email a second time. Here is an example:
PHP Code:
$host = 'localhost:143';
$user = 'user@domain.com';
$password = 'password';
$mailbox = "{$host}INBOX";
$mbx = imap_open($mailbox , $user , $password);
/*imap_check returns information about the mailbox
including mailbox name and number of messages*/
$check = imap_check($mbx);
/*imap_fetch_overview returns an overview for a message.
An overview contains information such as message subject,
sender, date, and if it has been seen. Note that it does
not contain the body of the message. Setting the second
parameter to "1:n" will cause it to return a sequence of messages*/
$overviews = imap_fetch_overview($mbx,"1:{$check->Nmsgs}");
foreach($overviews as $o)
{
if(!$o->answered) // if the email has not yet be replied to
{
$recipient = $o->from;
//use imap_mail() to send your message
//mark the email as answered
imap_setflag_full($mbx, $o->uid, "\\Answered", ST_UID);
}
}
The above code will reply to all unanswered emails, marking them as answered along the way.
More info on the imap functions:
http://tinsology.net/2009/04/accessi...map-using-php/
http://tinsology.net/2009/04/php-imap-notes/
Last edited by NullPointer; 11-17-2009 at 02:08 PM..
|