Spent ages trying to get this to work, then eventually remembered I had opened the mailbox READONLY - obviously you need write permission for setting flags!(PHP 4, PHP 5, PHP 7, PHP 8)
imap_setflag_full — Establece un flag en un mensaje
   imap_setflag_full() asigna el
   flag especificado a los mensajes de la
   sequence dada.
  
imapAn IMAP\Connection instance.
sequence
       Una secuencia de números de mensajes. Los mensajes deseados pueden ser enumerados con la sintaxis X,Y, o
       recuperar todos los mensajes de un intervalo con la sintaxis
       X:Y
      
flag
       Los flags que pueden ser modificados son \Seen,
       \Answered, \Flagged,
       \Deleted, y \Draft (como se define en
       la » RFC2060).
      
options
       options es una máscara de bits, que acepta
       únicamente el siguiente valor:
       
ST_UID - la secuencia contiene UID en lugar de
          números de secuencia.
         
        
   Retorna siempre true.
  
   Lanza una excepción ValueError si el argumento options es inválido.
  
| Versión | Descripción | 
|---|---|
| 8.1.0 | The imapparameter expects an IMAP\Connection
  instance now; previously, a validimapresource was expected. | 
| 8.0.0 | Una excepción ValueError es ahora lanzada
       para valores de argumento optionsinválidos. Anteriormente,
       se emitía una advertencia y la función devolvíafalse. | 
Ejemplo #1 Ejemplo con imap_setflag_full()
<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password")
     or die("Conexión imposible: " . imap_last_error());
$status = imap_setflag_full($mbox, "2,5", "\\Seen \\Flagged");
echo gettype($status) . "\n";
echo $status . "\n";
imap_close($mbox);
?>Spent ages trying to get this to work, then eventually remembered I had opened the mailbox READONLY - obviously you need write permission for setting flags!Where possible I would avoid using POP3 accounts. My host allowed me to upgrade to IMAP and it is so much easier. I think the only way to accurately create any form of mail client with POP3 is to download the messages into an SQL database which is a big task to start with, considering the IMAP standards have the functionality we need built in.
I experimented with flag setting in POP3 and it seems they do not stick at all, and it is almost impossible to retrieve the number of unread messages (ie. the Seen / Unseen thing does not work)
Converted to IMAP and it's working - the majority of the functions in this section seem to be IMAP focussed and WILL NOT generally work with POP3