通过php代码访问我的gmail收件箱

发布于 2024-08-04 04:31:07 字数 137 浏览 6 评论 0原文

我如何通过我的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北城挽邺 2024-08-11 04:31:07

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

<?php
    $mailbox = imap_open("{imap.googlemail.com:993/ssl}INBOX", "[email protected]", "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)

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

<?php
    $mailbox = imap_open("{imap.googlemail.com:993/ssl}INBOX", "[email protected]", "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);
?>

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)

嘦怹 2024-08-11 04:31:07

这对我有用。

<?php

$yourEmail = "[email protected]";
$yourEmailPassword = "your password";

$mailbox = imap_open("{imap.gmail.com:993/ssl}INBOX", $yourEmail, $yourEmailPassword);
$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);
?>

This works for me.

<?php

$yourEmail = "[email protected]";
$yourEmailPassword = "your password";

$mailbox = imap_open("{imap.gmail.com:993/ssl}INBOX", $yourEmail, $yourEmailPassword);
$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);
?>
不念旧人 2024-08-11 04:31:07

您可以从 PHP 使用 IMAP

<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password")
     or die("can't connect: " . imap_last_error());

$status = imap_setflag_full($mbox, "2,5", "\\Seen \\Flagged");

echo gettype($status) . "\n";
echo $status . "\n";

imap_close($mbox);
?>

You can use IMAP from PHP.

<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password")
     or die("can't connect: " . imap_last_error());

$status = imap_setflag_full($mbox, "2,5", "\\Seen \\Flagged");

echo gettype($status) . "\n";
echo $status . "\n";

imap_close($mbox);
?>
久伴你 2024-08-11 04:31:07

另一个不错的 IMAP 示例位于 http://davidwalsh.name/gmail-php-imap

Another nice IMAP example is available at http://davidwalsh.name/gmail-php-imap

稀香 2024-08-11 04:31:07

Zend Framework 也有用于读取邮件的 Zend_Mail API。如果需要的话,它可以轻松切换协议(POP3、IMAP、Mbox 和 Maildir)。目前只有 IMAP 和 Maildir 存储类支持设置标志。

http://framework.zend.com/manual/en/zend。 mail.read.html

从 Zend Framework 文档中读取消息示例:

$mail = new Zend_Mail_Storage_Pop3(array('host'     => 'localhost',
                                         'user'     => 'test',
                                         'password' => 'test'));

echo $mail->countMessages() . " messages found\n";
foreach ($mail as $message) {
    echo "Mail from '{$message->from}': {$message->subject}\n";
}

Zend Framework has the Zend_Mail API for reading mail as well. It makes it easy to switch protocols if need be (POP3, IMAP, Mbox, and Maildir). Only the IMAP and Maildir storage classes support setting flags at this time.

http://framework.zend.com/manual/en/zend.mail.read.html

Read messages example from the Zend Framework docs:

$mail = new Zend_Mail_Storage_Pop3(array('host'     => 'localhost',
                                         'user'     => 'test',
                                         'password' => 'test'));

echo $mail->countMessages() . " messages found\n";
foreach ($mail as $message) {
    echo "Mail from '{$message->from}': {$message->subject}\n";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文