Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $imapPath = '{imap.yandex.ru:993/imap/ssl}INBOX';
- $username = 'mapi@vteleport.ru';
- $password = 'C1B684q0';
- // try to connect
- $inbox = imap_open($imapPath, $username, $password) or die('Cannot connect to mail server: ' . imap_last_error());
- // Ищем только непрочитанные с темой Telezaim
- $emails = imap_search($inbox, 'UNSEEN SUBJECT "Telezaim"');
- if ($emails) { // если есть подходящие email, проводим с ними работу
- $unread_emails = jn(',', $emails);
- $status = imap_setflag_full($inbox, $unread_emails, "\\Seen");// Помечаю сообщения как проичтанные
- $output = [];
- foreach ($emails as $mail) {
- $headerInfo = imap_headerinfo($inbox, $mail);
- $personal = 'NO NAME';
- $email = 'NO EMAIL';
- if (isset($headerInfo->from[0]->personal)) {
- $personal = iconv_mime_decode($headerInfo->from[0]->personal);
- }
- if (isset($headerInfo->from[0]->mailbox) && isset($headerInfo->from[0]->host)) {
- $email = $headerInfo->from[0]->mailbox . '@' . $headerInfo->from[0]->host;
- }
- $output[] = array($personal, $email);
- }
- if ($output) { // если есть результаты для записи в файл, переходим к дописыванию
- $fp = fopen(root . '.log/.telezaim.app-' . date('Ymd') . '.csv', 'a');
- foreach ($output as $fields) {
- fputcsv($fp, $fields, ';');
- }
- fclose($fp);
- }
- }
- //colse the connection
- imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement