What are some common methods for retrieving emails from a pop3 server using PHP?

To retrieve emails from a POP3 server using PHP, you can use the built-in IMAP extension. This extension allows you to connect to a POP3 server, retrieve emails, and perform various actions on them. You can use functions like imap_open, imap_search, and imap_fetchheader to access and manipulate emails.

$hostname = '{pop3.example.com:110/pop3}INBOX';
$username = 'your_username';
$password = 'your_password';

$mailbox = imap_open($hostname, $username, $password);

if ($mailbox) {
    $emails = imap_search($mailbox, 'ALL');

    if ($emails) {
        foreach ($emails as $email_number) {
            $header = imap_fetchheader($mailbox, $email_number);
            echo $header;
        }
    }

    imap_close($mailbox);
}