Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
| Both sides previous revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
php:imap [2021/02/27 11:36] webproducer Auslesen von Dateianhängen ergänzt |
php:imap [2022/08/17 10:49] (aktuell) webproducer SSL ergänzt |
||
|---|---|---|---|
| Zeile 15: | Zeile 15: | ||
| private $username = ''; | private $username = ''; | ||
| private $password = ''; | private $password = ''; | ||
| + | private $port = 143; | ||
| + | private $type = 'IMAP'; | ||
| + | private $ssl = true; | ||
| /** | /** | ||
| Zeile 23: | Zeile 26: | ||
| public function getEmails( $onlyUnread = false ) | public function getEmails( $onlyUnread = false ) | ||
| { | { | ||
| - | $mailbox = sprintf( "{%s:143}INBOX", $this->server ); | + | $ssl = ''; |
| + | |||
| + | if( $this->ssl ) | ||
| + | { | ||
| + | $ssl = '/ssl'; | ||
| + | } | ||
| + | |||
| + | $mailbox = sprintf( "{%s:%d/%s%s/novalidate-cert}INBOX", $this->server, $this->port, $this->type, $ssl ); | ||
| $this->stream = imap_open( $mailbox, $this->username, $this->password ); | $this->stream = imap_open( $mailbox, $this->username, $this->password ); | ||
| $MC = imap_check( $this->stream ); | $MC = imap_check( $this->stream ); | ||
| Zeile 70: | Zeile 80: | ||
| public function close() | public function close() | ||
| { | { | ||
| - | imap_close( $this->stream ); | + | if( $this->stream !== false ) |
| + | { | ||
| + | imap_close( $this->stream ); | ||
| + | } | ||
| } | } | ||
| } | } | ||
| Zeile 97: | Zeile 110: | ||
| ---- | ---- | ||
| - | ===== Beispiel für Dateianhänge ===== | + | ===== Beispiel für Dateianhänge (Attachments) ===== |
| <code php> | <code php> | ||
| Zeile 105: | Zeile 118: | ||
| foreach( $emails as $email ) | foreach( $emails as $email ) | ||
| { | { | ||
| - | $attamchent = $imap->getAttachments( $email->uid ); | + | $attachment = $imap->getAttachments( $email->uid ); |
| - | if( $attamchent !== false ) | + | if( $attachment !== false ) |
| { | { | ||
| - | echo "Anhang gefunden: " . $attamchent; | + | echo "Anhang gefunden: " . $attachment; |
| } | } | ||
| } | } | ||
| </code> | </code> | ||