...

View Full Version : EMail Deletion



jfreak53
08-07-2007, 12:14 AM
Looking for a simple PHP code that will open a mailbox in pop3 and then delete all the mail that's in the said box then exit?

Thanks in advance..

Crazydog
08-07-2007, 12:27 AM
download pop3.class.inc (http://www.phpclasses.org/browse/package/1120.html)

This gets the email


require('pop3.class.inc');

$do = $pop3->connect ('pop3.server.com');
if ($do == false) {
die($pop3->error);
}

$do = $pop3->login ('email@address.com','password');

if ($do == false) {
die($pop3->error);
}
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);

$email = $pop3->get_mail($i);


And this will delete the email


$do = $pop3->delete_mail (1);
if ($do == false)
{
echo $pop3->error;
}

jfreak53
08-07-2007, 02:43 AM
I get this error:


Fatal error: Call to a member function on a non-object in c:\appserv\www\joel.php on line 5

Line 5 is this:


$do = $pop3->connect ('pop3.server.com');

TheShaner
08-07-2007, 03:01 AM
You should probably post your code, esp. line 5 so we know what the code looks like that is getting the error.

-Shane

jfreak53
08-07-2007, 03:21 AM
Code for the page:


<?

require('pop3.class.inc');

$do = $pop3->connect ('server');
if ($do == false) {
die($pop3->error);
}

$do = $pop3->login ('user','pass');

if ($do == false) {
die($pop3->error);
}
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);

$email = $pop3->get_mail($i);

$do = $pop3->delete_mail (1);
if ($do == false)
{
echo $pop3->error;
}
}
?>

TheShaner
08-07-2007, 03:34 AM
Ok, so I'm guessing line 5 is:

$do = $pop3->connect ('server');
Well, it looks like you haven't created the pop3 object.

I'm not sure what the readme says or what the example shows, but you'll need a line similar to:

$pop3 = new POP3();
Look at the example that is provided on the link Crazydog gave you for the exact name to use.

-Shane

jfreak53
08-07-2007, 02:03 PM
Ok, this finally works, thanks. Now for one more thing. Since it only deletes the first email, how do I get it to get a full list of emails and delete each one?

TheShaner
08-07-2007, 03:25 PM
Again, read through the readme and example. You'll see that $do = $pop3->delete_mail (1); has the number 1, which means it's deleting the first email (or 2nd if it starts at 0). What you will need to do is loop through and delete each one.

EX:

for ($i=1; $i<=$pop3->count_mail(); $i++)
$do = $pop3->delete_mail ($i);
In the above code, I guessed that there was a count_mail() method, but there may not be. You just have to find out how to get the total number of emails and then use that number as your max so that you can loop through each email and delete it.

-Shane

jfreak53
08-07-2007, 11:58 PM
Ok I dug through the code in the sample file and found this:


for($i=1;$i<=$msg_list["count_mails"];$i++)

So I copied it and am using it, this is the code that I have:


<?

require('pop3.class.inc');

$pop3 = new POP3();

$do = $pop3->connect ('server');
if ($do == false) {
die($pop3->error);
echo "error1";
}

$do = $pop3->login ('user','pass');

if ($do == false) {
die($pop3->error);
echo "error2";
}
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);
echo "error3";
}

$email = $pop3->get_mail($i);

if(!$msg_list = $pop3->get_office_status()){
echo $pop3->error;
return;
}

for($i=1;$i<=$msg_list["count_mails"];$i++){
$do = $pop3->delete_mail ($i);
if ($do == false)
{
echo $pop3->error;
echo "error";
}
}

?>

I get no errors it just runs and stops and nothing. Doesn't delete anything, what am I doing wrong here?

jfreak53
08-08-2007, 02:40 PM
Duh, sorry guys, I wasn't closing the connection. I had it in the original script but I forgot that I deleted it and wasn't closing it. So problem solved script now working. Thanks for all the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum