PHP - How to access and retrieve important data from a pop3 email account?

狂风中的少年 提交于 2019-12-08 10:50:47

问题


I am trying to create a php program that will check for the presence of any emails with a keyword in the subject line, then it will retrieve the contents of the email and pass it to a variable.

Can anyone provide me with some helpful information on how to accomplish this?


回答1:


If you can use imap protocol better, you can try the imap functions of PHP

<?php
    $imap = imap_open("{mail.yourserver.com:143}INBOX", "username", "password");
    $message_count = imap_num_msg($imap);

    for ($i = 1; $i <= $message_count; ++$i) {
        $header = imap_header($imap, $i);
        if (preg_match('#keyword#',$header['subject'])) {
             $body = imap_body($imap, $i);
             // your action here
        }
    }

    imap_close($imap);
?> 


来源:https://stackoverflow.com/questions/11181450/php-how-to-access-and-retrieve-important-data-from-a-pop3-email-account

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!