首页 > 其他 > 详细

获取邮箱的邮件

时间:2019-09-06 22:01:22      阅读:98      评论:0      收藏:0      [点我收藏+]
1. 安装扩展imap
技术分享图片
2.composer下载
composer require php-imap/php-imap
包地址:
技术分享图片
 
3.使用
public function read_email(){
        // Create PhpImap\Mailbox instance for all further actions
        $mailbox = new \PhpImap\Mailbox(
            ‘{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(\PhpImap\Exceptions\ConnectionException $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 "\nMail has attachments? ";//是有有附件
        if($mail->hasAttachments()) {
            echo "Yes\n";
        } else {
            echo "No\n";
        }
 
        // Print all information of $mail
        dd($mail);
 
        // Print all attachements of $mail
        echo "\n\nAttachments:\n";
        dd($mail->getAttachments());//附件
    }
 
 
 
注:
设置收信的范围
技术分享图片
 

获取邮箱的邮件

原文:https://www.cnblogs.com/wmc1125/p/11478163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!