PHP - How to access and retrieve important data fr

2019-06-10 06:24发布

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?

标签: php email pop3
1条回答
一纸荒年 Trace。
2楼-- · 2019-06-10 07:07

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);
?> 
查看更多
登录 后发表回答