Refreshing the inbox before reading mails thru PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Refreshing the inbox before reading mails thru PHP

Post by siji86 »

Hi,
Is there any PHP function to refresh a mailbox before reading it. I searched for imap functions, but der isn't any function to refresh the mailbox.
Any Idea?

Thanks in advance
Elizabeth. :)
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: Refreshing the inbox before reading mails thru PHP

Post by roders »

Tricky question, you want to refresh the mailbox before reading an email or before seeing the mailbox, can you elaborate on that please? thanks.
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Re: Refreshing the inbox before reading mails thru PHP

Post by siji86 »

Hi,

I want to refresh the mailbox before seeing the mailbox to get the most recent mails.

Thanks.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Refreshing the inbox before reading mails thru PHP

Post by Weiry »

i have no idea what your on about.. or what sort of mailbox you want help with.

Before Post Read: General Posting Guidelines
6. Write your question carefully, think about what you need to achieve and exactly what help you are looking for.
7. Write a clear subject line, it'll help people deciding whether to look at your post or not - 'help, PHP noob' is probably going to be ignored by some.
While you completed #7 barley, you may want to read #6 again.
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Re: Refreshing the inbox before reading mails thru PHP

Post by siji86 »

ok, let me elaborate with some code that i have written.

I am using imap function in php to open a particular mailbox (inbox) and fetch the mails. Particularly i want to fetch all bounced mails. So following is the code:

$hostname="{124.163.948.918:110/pop3/novalidate-cert}INBOX";
$username = 'dfgd';
$password = 'dgdooopoo';


$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Graphserver: ' . imap_last_error());
$emails = imap_search($inbox,'SUBJECT "Undelivered Mail Returned to Sender" ');

rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,1);
$message = imap_fetchbody($inbox,$email_number,1);
$find= "To: "; // look for the 'To' part
$foundatloc= strpos($message,$find);
if ($foundatloc > 1){ // test if a mail adres was found
$findend = "\n";
$foundendloc = strpos($message,$findend,$foundatloc); // find the location of EOL
$foundendloc = $foundendloc -($foundatloc + 5);
$adres = substr($message,$foundatloc + 5,$foundendloc);
$adres = str_replace("<","",$adres); // strip <, > and spaces
$adres = str_replace(">","",$adres);
$adres = trim($adres);
$arr=explode(' ',$adres);
print($arr[1]);
//$arr[1] contains the bounced address !!!
}
else{
$listemails = extract_emails_from($message);
print(implode("\n", $listemails));
}


print('<br>');
}

//There is a function that sends the mail

//After that i call the above code to catch bounced mails

Now, the problem is that i do not get the most recent bounced mail, i get it only the next time i run this script. So i am finding some way to refresh the inbox before fetching the mails.

I hope my problem is clear now.
pls help....
:?
Post Reply