Delete email from mail server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hamayun Khan
    New Member
    • Aug 2007
    • 106

    Delete email from mail server

    Hello !

    I'm looking for a script which allows me to read emails and attachment
    from a pop server (then I'll save the email's text in a db and the
    attachments on the server).

    So I have found this article: http://www.phpit.net/article/read-email-php-pop3/

    ....
    $email = $pop3->get_mail($i) ; // how to get the email
    ....

    i write the code below to delete the mail from mail server
    [code=php]
    $do = $pop3->delete_mail (1);
    if ($do == false)
    {
    echo $pop3->error;
    }[/code]

    this doesn't work

    anyone help me

    Thanks a lot
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Hamayun. Welcome to TSDN!

    What do you want your code to do? Give an example.
    What is your code doing that you don't want it to do? Give an example.
    What is your code *not* doing that it is supposed to? Give an example.

    Comment

    • Hamayun Khan
      New Member
      • Aug 2007
      • 106

      #3
      Thanks Moderator

      I have download pop3.class.inc class from Php classes
      using this class i read email from my mailbox.

      [code=php]
      $do = $pop3->connect ('mail.h1brecru iting.com');
      if ($do == false) {
      die($pop3->error);
      }

      $do = $pop3->login ('hama@h1brecru iting.com','xxx xxxx');

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

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

      $email = $pop3->get_mail($i) ;[/code]

      the above code read email $i from hama@h1brecruit ing.com and i perform required operation. Now i want to delete this email from hama@h1brecurit ing.com. For which i use
      [code=php]
      $do = $pop3->delete_mail (1);
      if ($do == false)
      {
      echo $pop3->error;
      }[/code]

      I use this to delete email No.1. but the emait is still in my INBOX.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Hamayun, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

        How are you checking to see if the email has been deleted? Are you logging on to a website, or are you using an email client?

        Comment

        • Hamayun Khan
          New Member
          • Aug 2007
          • 106

          #5
          I m using an email client.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Hamayun.

            Many email clients store copies of the email from the server. So it is possible that the email actually *has* been deleted, but your email client is still showing you the saved copy.

            Comment

            • Hamayun Khan
              New Member
              • Aug 2007
              • 106

              #7
              Salam

              Is there any possibility to delete email from my email client

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, Hamayun.

                It is possible, though the results are unpredictable, since it depends on the application.

                If your email server has a web-based interface, that's the safest and most reliable way to verify that the email has been deleted.

                Comment

                • Hamayun Khan
                  New Member
                  • Aug 2007
                  • 106

                  #9
                  Salam

                  Let say that i have only one email in my inbox when i execute the code below
                  [code=php]
                  require ('pop3.class.in c'); //POP3 class

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

                  $do = $pop3->login ('hama@example. com','xxxxxxx') ;

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

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

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

                  This code execute successfully and i get the email

                  Now when i execute the code to delete which is below

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

                  the code execute successfully generating no errors but when i again execute the code

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

                  $do = $pop3->login ('hama@example. com','xxxxxxx') ;

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

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

                  $email = $pop3->get_mail(1);
                  [/code]

                  for retrieving email again the code execute successfully and I get the email.
                  Now when I delete the email by signin to my email account and I have no email in my account then both the codes for deleting and retrievig email generat error.

                  The below error is generated.

                  POP3 delete_mail() - Error: -ERR Invalid message number.

                  Now I have the problem to delete the mail through php code.
                  I think the delete function of pop3 class doesn't work well.

                  Comment

                  • Hamayun Khan
                    New Member
                    • Aug 2007
                    • 106

                    #10
                    Salam and thanks
                    my problem has been solved.

                    after the DELE msg
                    there was no QUIT command executed in the class
                    [code=php]
                    Pop3->delete($msgno) ;
                    Pop3->close();[/code]
                    this solve my problem

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #11
                      Heya, Hamayun.

                      Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

                      Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

                      Comment

                      Working...