通过 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)
相关文章