PHP - How to access and retrieve important data fr

2019-06-10 06:32发布

问题:

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


标签: php email pop3