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

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

问题描述

我可以通过我的php代码访问我的Gmail帐户吗?我需要从我的Gmail帐户获取主题和地址。然后我需要将访问标记为在gmail上读取
我应该使用gmail pop3 clint吗?是否可以用于访问gmail的任何框架pop3
server。

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服务器),设置$主题为第一条消息和$ from到第一条消息的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天全站免登陆