Hướng dẫn barbushin php console - bảng điều khiển php barbushin
Show
Ban đầu được phát hành vào tháng 12 năm 2012, hộp thư IMAP PHP là một thư viện nguồn mở và mạnh mẽ để kết nối với hộp thư của POP3, IMAP và NNTP bằng cách sử dụng tiện ích mở rộng IMAP PHP. Thư viện này cho phép bạn tìm nạp email từ máy chủ email của bạn. Mở rộng chức năng hoặc tạo các ứng dụng web mạnh mẽ để xử lý các email đến của bạn. Đặc trưng
Yêu cầu
Php $ composer require php-imap/php-imap:dev-master 3 mở rộng phải có mặt; Vì vậy, hãy chắc chắn rằng dòng này đang hoạt động trong php.ini của bạn: $ composer require php-imap/php-imap:dev-master 4Php 5 mở rộng phải có mặt; Vì vậy, hãy chắc chắn rằng dòng này đang hoạt động trong php.ini của bạn: 6
Cài đặt bởi nhà soạn nhạc
Cài đặt bản phát hành mới nhất có sẵn:Cài đặt mã nguồn ổn định và có sẵn mới nhất từ 7, có thể chưa được phát hành / gắn thẻ:Chạy các bài kiểm traTrước khi bạn có thể chạy bất kỳ thử nghiệm nào, bạn có thể cần chạy 8 để cài đặt tất cả các phụ thuộc (phát triển).Chạy tất cả các bài kiểm traBạn có thể chạy tất cả các thử nghiệm có sẵn bằng cách chạy lệnh sau (bên trong thư mục 9 đã cài đặt): // Create PhpImap\Mailbox instance for all further actions $mailbox = new PhpImap\Mailbox( '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder '', // Username for the before configured mailbox '*********', // Password for the before configured username __DIR__, // Directory, where attachments will be saved (optional) 'UTF-8', // Server encoding (optional) true, // Trim leading/ending whitespaces of IMAP path (optional) false // Attachment filename mode (optional; false = random filename; true = original filename) ); // set some connection arguments (if appropriate) $mailbox->setConnectionArgs( CL_EXPUNGE // expunge deleted mails upon mailbox close | OP_SECURE // don't do non-secure authentication ); try { // Get all emails (messages) // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php $mailsIds = $mailbox->searchMailbox('ALL'); } catch(PhpImap\Exceptions\ConnectionException $ex) { echo "IMAP connection failed: " . implode(",", $ex->getErrors('all')); die(); } // If $mailsIds is empty, no emails could be found if(!$mailsIds) { die('Mailbox is empty'); } // Get the first message // If '__DIR__' was defined in the first line, it will automatically // save all attachments to the specified directory $mail = $mailbox->getMail($mailsIds[0]); // Show, if $mail has one or more attachments echo "\nMail has attachments? "; if($mail->hasAttachments()) { echo "Yes\n"; } else { echo "No\n"; } // Print all information of $mail print_r($mail); // Print all attachements of $mail echo "\n\nAttachments:\n"; print_r($mail->getAttachments());0 Chỉ chạy các bài kiểm tra phpunit
Tích hợp với các khungSymfony-https://github.com/secit-pl/imap-bundle Bắt đầu ví dụ // Create PhpImap\Mailbox instance for all further actions $mailbox = new PhpImap\Mailbox( '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder '', // Username for the before configured mailbox '*********', // Password for the before configured username __DIR__, // Directory, where attachments will be saved (optional) 'UTF-8', // Server encoding (optional) true, // Trim leading/ending whitespaces of IMAP path (optional) false // Attachment filename mode (optional; false = random filename; true = original filename) ); // set some connection arguments (if appropriate) $mailbox->setConnectionArgs( CL_EXPUNGE // expunge deleted mails upon mailbox close | OP_SECURE // don't do non-secure authentication ); try { // Get all emails (messages) // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php $mailsIds = $mailbox->searchMailbox('ALL'); } catch(PhpImap\Exceptions\ConnectionException $ex) { echo "IMAP connection failed: " . implode(",", $ex->getErrors('all')); die(); } // If $mailsIds is empty, no emails could be found if(!$mailsIds) { die('Mailbox is empty'); } // Get the first message // If '__DIR__' was defined in the first line, it will automatically // save all attachments to the specified directory $mail = $mailbox->getMail($mailsIds[0]); // Show, if $mail has one or more attachments echo "\nMail has attachments? "; if($mail->hasAttachments()) { echo "Yes\n"; } else { echo "No\n"; } // Print all information of $mail print_r($mail); // Print all attachements of $mail echo "\n\nAttachments:\n"; print_r($mail->getAttachments()); Dưới đây, bạn sẽ tìm thấy một mã ví dụ về cách bạn có thể sử dụng thư viện này. Để biết thêm thông tin và các ví dụ khác, bạn có thể xem Wiki. // Call imap_check() - see http://php.net/manual/function.imap-check.php $info = $mailbox->imap('check'); // Show current time for the mailbox $currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown'; echo $currentServerTime; Theo mặc định, thư viện này sử dụng tên tệp ngẫu nhiên cho các tệp đính kèm làm tên tệp giống hệt nhau từ các email khác sẽ ghi đè lên các tệp đính kèm khác. Nếu bạn muốn giữ tên tệp gốc, bạn có thể đặt chế độ tệp đính kèm thành // Create PhpImap\Mailbox instance for all further actions $mailbox = new PhpImap\Mailbox( '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder '', // Username for the before configured mailbox '*********', // Password for the before configured username __DIR__, // Directory, where attachments will be saved (optional) 'UTF-8', // Server encoding (optional) true, // Trim leading/ending whitespaces of IMAP path (optional) false // Attachment filename mode (optional; false = random filename; true = original filename) ); // set some connection arguments (if appropriate) $mailbox->setConnectionArgs( CL_EXPUNGE // expunge deleted mails upon mailbox close | OP_SECURE // don't do non-secure authentication ); try { // Get all emails (messages) // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php $mailsIds = $mailbox->searchMailbox('ALL'); } catch(PhpImap\Exceptions\ConnectionException $ex) { echo "IMAP connection failed: " . implode(",", $ex->getErrors('all')); die(); } // If $mailsIds is empty, no emails could be found if(!$mailsIds) { die('Mailbox is empty'); } // Get the first message // If '__DIR__' was defined in the first line, it will automatically // save all attachments to the specified directory $mail = $mailbox->getMail($mailsIds[0]); // Show, if $mail has one or more attachments echo "\nMail has attachments? "; if($mail->hasAttachments()) { echo "Yes\n"; } else { echo "No\n"; } // Print all information of $mail print_r($mail); // Print all attachements of $mail echo "\n\nAttachments:\n"; print_r($mail->getAttachments());3, nhưng sau đó bạn cũng cần đảm bảo rằng các tệp đó không bị ghi đè bởi các email khác chẳng hạn. // If you don't need to grab attachments you can significantly increase performance of your application $mailbox->setAttachmentsIgnore(true); // get the list of folders/mailboxes $folders = $mailbox->getMailboxes('*'); // loop through mailboxs foreach($folders as $folder) { // switch to particular mailbox $mailbox->switchMailbox($folder['fullpath']); // search in particular mailbox $mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"'); } print_r($mails_ids); Phương thức // Create PhpImap\Mailbox instance for all further actions $mailbox = new PhpImap\Mailbox( '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder '', // Username for the before configured mailbox '*********', // Password for the before configured username __DIR__, // Directory, where attachments will be saved (optional) 'UTF-8', // Server encoding (optional) true, // Trim leading/ending whitespaces of IMAP path (optional) false // Attachment filename mode (optional; false = random filename; true = original filename) ); // set some connection arguments (if appropriate) $mailbox->setConnectionArgs( CL_EXPUNGE // expunge deleted mails upon mailbox close | OP_SECURE // don't do non-secure authentication ); try { // Get all emails (messages) // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php $mailsIds = $mailbox->searchMailbox('ALL'); } catch(PhpImap\Exceptions\ConnectionException $ex) { echo "IMAP connection failed: " . implode(",", $ex->getErrors('all')); die(); } // If $mailsIds is empty, no emails could be found if(!$mailsIds) { die('Mailbox is empty'); } // Get the first message // If '__DIR__' was defined in the first line, it will automatically // save all attachments to the specified directory $mail = $mailbox->getMail($mailsIds[0]); // Show, if $mail has one or more attachments echo "\nMail has attachments? "; if($mail->hasAttachments()) { echo "Yes\n"; } else { echo "No\n"; } // Print all information of $mail print_r($mail); // Print all attachements of $mail echo "\n\nAttachments:\n"; print_r($mail->getAttachments());4 cho phép gọi bất kỳ chức năng IMAP PHP nào trong bối cảnh của trường hợp. Thí dụ:Một số yêu cầu yêu cầu nhiều thời gian và tài nguyên: Before: public function checkMailbox() { return $this->imap('check'); } After: public function checkMailbox(): object { return Imap::check($this->getImapStream()); } Nâng cấp từ 3.x
|