zoukankan      html  css  js  c++  java
  • 获取邮箱的邮件

    1. 安装扩展imap
    2.composer下载
    composer require php-imap/php-imap
    包地址:
     
    3.使用
    public function read_email(){
            // Create PhpImapMailbox instance for all further actions
            $mailbox = new PhpImapMailbox(
                '{imap.qq.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
                '287851074@qq.com', // 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)
            );
     
            try {
                // Get all emails (messages)
                // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php
                $mailsIds = $mailbox->searchMailbox('ALL');
            } catch(PhpImapExceptionsConnectionException $ex) {
                echo "IMAP connection failed: " . $ex;
                die();
            }
            // dd($mailsIds);
            // 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 "
    Mail has attachments? ";//是有有附件
            if($mail->hasAttachments()) {
                echo "Yes
    ";
            } else {
                echo "No
    ";
            }
     
            // Print all information of $mail
            dd($mail);
     
            // Print all attachements of $mail
            echo "
    
    Attachments:
    ";
            dd($mail->getAttachments());//附件
        }
     
     
     
    注:
    设置收信的范围
     
  • 相关阅读:
    django migration
    Jenkins Jobs status dashboard by Build Monitor Plugin
    PyWebIO Write interactive web app in script way.
    Infrastructure as Code
    sqlalchemy
    reactsketch
    CI/CD System and gerrittrigger keypoints.
    mysql backup
    Alembic A database migrations tool for SQLAlchemy.
    docker support for inner loop
  • 原文地址:https://www.cnblogs.com/wmc1125/p/11478163.html
Copyright © 2011-2022 走看看