通过 php 代码访问我的 gmail 收件箱 [英] accessing my gmail inbox via php code

查看:21
本文介绍了通过 php 代码访问我的 gmail 收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过我的 php 代码访问我的 gmail 帐户?我需要从我的gmail帐户中获取主题和发件人地址.然后我需要在gmail上将访问标记为已读我应该使用 gmail pop3 clint 吗?这是我可以用来访问 gmail pop3 的任何框架吗?服务器.

how i can access my gmail account through my php code? I need to get the subject and the from address to from my gmail account.And then i need to mark the accessed as read on gmail Should i use gmail pop3 clint?is that any framework that i can use for accessing gmail pop3 server.

推荐答案

我只会使用 PHP imap 函数 并执行以下操作:

I would just use the PHP imap functions and do something like this:

<?php
    $mailbox = imap_open("{imap.googlemail.com:993/ssl}INBOX", "USERNAME@googlemail.com", "PASSWORD");
    $mail = imap_search($mailbox, "ALL");
    $mail_headers = imap_headerinfo($mailbox, $mail[0]);
    $subject = $mail_headers->subject;
    $from = $mail_headers->fromaddress;
    imap_setflag_full($mailbox, $mail[0], "\Seen \Flagged");
    imap_close($mailbox);
?>

这会连接到 imap.googlemail.com(googlemail 的 imap 服务器),将 $subject 设置为第一封邮件的主题,并将 $from 设置为第一封邮件的发件人地址.然后,它将这条消息标记为已读.(它未经测试,但它应该工作:S)

This connects to imap.googlemail.com (googlemail's imap server), sets $subject to the subject of the first message and $from to the from address of the first message. Then, it marks this message as read. (It's untested, but it should work :S)

这篇关于通过 php 代码访问我的 gmail 收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆