20.3 E-Mail mit IMAP oder POP3 lesen

Problem

Sie wollen E-Mail mit IMAP oder POP3 lesen, wodurch Sie ein webbasiertes E-Mail-Client-Programm erstellen können.

Lösung

Verwenden Sie die IMAP-Erweiterung von PHP, die sowohl IMAP als auch POP3 spricht:

// IMAP-Verbindung öffnen. $mail = imap_open('{mail.server.com:143}', 'username', 'password'); // Oder: POP3-Verbindung öffnen. $mail = imap_open('{mail.server.com:110/pop3}', 'username', 'password'); // Liste aller E-Mail-Header herunterladen. $headers = imap_headers($mail); // Header-Objekt der letzten Nachricht in der Mailbox herunterladen. $last = imap_num_msg($mail); $header = imap_header($mail, $last); // Body derselben Nachricht holen. $body = imap_body($mail, $last); // Verbindung schließen. imap_close($mail); ...

Get PHP 5 Kochbuch, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.