Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: EMail Deletion

  1. #1
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts

    EMail Deletion

    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..

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    download pop3.class.inc (http://www.phpclasses.org/browse/package/1120.html)

    This gets the email
    PHP Code:
    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
    PHP Code:
          $do $pop3->delete_mail (1);
          if (
    $do == false)
          {
          echo 
    $pop3->error;
          } 
    Last edited by Crazydog; 08-06-2007 at 11:30 PM.

  • #3
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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');
    Last edited by jfreak53; 08-07-2007 at 02:02 AM.

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    You should probably post your code, esp. line 5 so we know what the code looks like that is getting the error.

    -Shane

  • #5
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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;
    }
    }
    ?>

  • #6
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Ok, so I'm guessing line 5 is:
    PHP Code:
    $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:
    PHP Code:
    $pop3 = new POP3(); 
    Look at the example that is provided on the link Crazydog gave you for the exact name to use.

    -Shane

  • #7
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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?

  • #8
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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:
    PHP Code:
    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

  • #9
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    Ok I dug through the code in the sample file and found this:

    Code:
    for($i=1;$i<=$msg_list["count_mails"];$i++)
    So I copied it and am using it, this is the code that I have:

    Code:
    <?
    
    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?

  • #10
    Regular Coder jfreak53's Avatar
    Join Date
    May 2004
    Location
    Guatemala
    Posts
    477
    Thanks
    19
    Thanked 10 Times in 10 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •