【问题标题】:accessing my gmail inbox via php code通过 php 代码访问我的 gmail 收件箱
【发布时间】:2010-11-26 00:39:33
【问题描述】:

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

【问题讨论】:

  • 你知道如果你接受一个答案你会得到+2分吗?这三个中的任何一个都可以。选择一个。

标签: php email gmail pop3


【解决方案1】:

http://davidwalsh.name/gmail-php-imap 上提供了另一个不错的 IMAP 示例

【讨论】:

    【解决方案2】:

    这对我有用。

    <?php
    
    $yourEmail = "you@gmail.com";
    $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);
    ?>
    

    【讨论】:

      【解决方案3】:

      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";
      }
      

      【讨论】:

        【解决方案4】:

        我会使用 PHP imap functions 并执行以下操作:

        <?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)

        【讨论】:

          【解决方案5】:

          您可以使用 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);
          ?>
          

          【讨论】:

            猜你喜欢
            • 2017-05-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-29
            • 1970-01-01
            • 2013-04-15
            • 2013-08-15
            相关资源
            最近更新 更多