Jump to content

Filtering Email using IMAP !


TomT

Recommended Posts

I've amended the script below and it works as expected.

 

What I would like to do is update it so I can move messages from INBOX to various IMAP folders based on specific criteria:

 

ie:

Subject contains **SPAM** move to 'Junk'

TO contains Tom move to 'Inbox.Tom'

FROM contains [email protected] move to Inbox.Ebay

 

think you get the idea

 

This my starting code:

 

Code:

<?php

/* connect to imap */
$hostname = '{127.0.0.1:143}INBOX';
$username = 'user';
$password = 'pass';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to $hostname: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

/* put the newest emails on top */
rsort($emails);

/* for every email... */
foreach($emails as $email_number) {

/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$msg_id=$overview[0]->msgno;
$subj=$overview[0]->subject;

imap_mail_move($inbox,$msg_id,'INBOX.New');

}

} 

/* close the connection */
imap_close($inbox);
?>

 

Any Ideas ? Thanks

Link to comment
https://forums.phpfreaks.com/topic/201338-filtering-email-using-imap/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.