<?
$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
imap_close($link);
$x=0;
for ( $i=1; $i < $total;$i++)
{
$link1 = imap_open($mailserver, $username, $password);
imap_delete($link1, $x);
$x++ ;
}
imap_expunge($link1);
imap_close($link1);
//The above code should delete all the mails on the mail server but it does not ???
//it some time delete one or some times 2 but not all of them
i am using windows(iis , and MDEAMON mail server )
?>
This code does not delete all the mails why ?
Moderator: General Moderators
-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
This also does't work
<?
$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
imap_close($link);
$x=0;
$link1 = imap_open($mailserver, $username, $password);
for ( $i=1; $i < $total;$i++)
{
imap_delete($link1, $x);
$x++ ;
}
imap_expunge($link1);
imap_close($link1);
//The above code should delete all the mails on the mail server but it does not ???
//it some time delete one or some times 2 but not all of them
i am using windows(iis , and MDEAMON mail server )
?>
<?
$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
imap_close($link);
$x=0;
$link1 = imap_open($mailserver, $username, $password);
for ( $i=1; $i < $total;$i++)
{
imap_delete($link1, $x);
$x++ ;
}
imap_expunge($link1);
imap_close($link1);
//The above code should delete all the mails on the mail server but it does not ???
//it some time delete one or some times 2 but not all of them
i am using windows(iis , and MDEAMON mail server )
?>
Code: Select all
<?php
$link = imap_open($mailserver, $username, $password); // connect to imap
$total = imap_num_msg($link); // get number of messages
imap_close($link); // disconnect from imap
$x=0;
$link1 = imap_open($mailserver, $username, $password); // link to imap... again.
for ( $i=1; $i < $total;$i++) // set $i to 1, as long as it is less than $total, add 1 to $i, but set it back to 1 at the start of each loop...
{
imap_delete($link1, $x); // delete the messages marked at $x (why not $i ?)
$x++ ; // add 1 to $x
}
// clean up
imap_expunge($link1);
imap_close($link1);
?>Never used imap before, too 
a little error-logging might be useful.
I think you miss one message.$i=1; $i < $total;$i++
a little error-logging might be useful.
Code: Select all
<?php
$link = imap_open($mailserver, $username, $password) or die('connection failed');
$total = imap_num_msg($link);
// debugInfo
oInfo = imap_mailboxmsginfo($link);
echo 'msgs: ', oInfo->Nmsgs, '<br/>';
// delete-loop
$i=0;
while($i < $total)
imap_delete($link, ++$i);
//debugInfo
echo 'deleted: ', oInfo->Deleted, '<br/>';
echo 'errors: ';
print_r(imap_errors());
echo '<br/>alerts: ';
print_r(imap_alerts());
// close connection after expunge
imap_close($link, CL_EXPUNGE);
?>