PHP - Fungsi imap_expunge ()

Fungsi PHP − IMAP membantu Anda mengakses akun email, singkatan dari IMAP Internet Mbersakit Aakses Protocol menggunakan fungsi ini, Anda juga dapat bekerja dengan NNTP, protokol POP3, dan metode akses kotak surat lokal.

Anda dapat menandai surat / pesan dari kotak surat tertentu untuk dihapus menggunakan salah satu fungsi imap_delete (), imap_mail_move (), atau imap_setflag_full ().

Itu imap_expunge() function menerima nilai resource yang mewakili streaming IMAP sebagai parameter dan, menghapus semua pesan yang ditandai untuk dihapus.

Sintaksis

imap_expunge($imap_stream);

Parameter

Sr Tidak Parameter & Deskripsi
1

imap_stream (Mandatory)

Ini adalah nilai string yang mewakili aliran IMAP, nilai kembalian dari imap_open() fungsi.

Kembalikan Nilai

Fungsi ini mengembalikan Boolean TRUE.

Versi PHP

Fungsi ini pertama kali diperkenalkan di PHP Versi 4 dan berfungsi di semua versi yang lebih baru.

Contoh

Contoh berikut menunjukkan penggunaan file imap_delete() fungsi -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
		 		 
         //Marking message for deletion
         $res = imap_delete($imap, 5);
         if($res){
            print("Message marked for deletion"."<br>");
         }		 
         //Deleting messages
         $res = imap_expunge($imap);	 	
         if($res){
            print("Message deleted");
         }		 		 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Keluaran

Ini akan menghasilkan keluaran berikut -

Connection established....
Message marked for deletion
Message deleted

Contoh

Berikut adalah contoh lain dari fungsi di atas -

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "[email protected]";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         print("Contents  of inbox: "."<br>");
         $emailData = imap_search($imap, '');
         foreach ($emailData as $msg) {
            $msg = imap_fetchbody($imap, $msg, "1");
            print(quoted_printable_decode($msg)."<br>");                
         }    
         //Marking message for deletion
         imap_delete($imap, 5);
         
         //Deleting messages
         imap_expunge($imap);	 		 
		 
         print("Contents of inbox after deletion: "."<br>");
         $emailData = imap_search($imap, '');
         foreach ($emailData as $msg) {
            $msg = imap_fetchbody($imap, $msg, "1");
            print(quoted_printable_decode($msg)."<br>");                
         }    
		 
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Keluaran

Ini akan menghasilkan keluaran berikut -

Connection established....
Contents of inbox:
#sample_mail1
#sample_mail2
#sample_mail3
#sample_mail4
#sample_mail5
Contents of inbox after deletion:
#sample_mail1
#sample_mail2
#sample_mail3
#sample_mail4

Language