PHP访问电子邮件收件箱以获取电子邮件地址

5

我需要获取我收件箱中接收/接收电子邮件的电子邮件地址!为此,我现在有以下代码

<?php
    $mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "address@gmail.com", "passw0rd")
      or die("can't connect: " . imap_last_error());

    $status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_MESSAGES);
    if ($status) {
      echo $status->messages;
    }
?>
1个回答

15
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'davidwalshblog@gmail.com';
$password = 'davidwalsh';

/* try to connect */
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email... */
    foreach($emails as $email_number) {

        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,0);


        $output.= 'Name:  '.$overview[0]->from.'</br>';
            $output.= 'Email:  '.$overview[0]->message_id.'</br>';



    }

    echo $output;
} 

/* close the connection */
imap_close($inbox);
?>

链接:从这里更新代码

编辑

subject - the messages subject
from - who sent it
to - recipient
date - when was it sent
message_id - Message-ID
references - is a reference to this message id
in_reply_to - is a reply to this message id
size - size in bytes
uid - UID the message has in the mailbox
msgno - message sequence number in the mailbox
recent - this message is flagged as recent
flagged - this message is flagged
answered - this message is flagged as answered
deleted - this message is flagged for deletion
seen - this message is flagged as already read
draft - this message is flagged as being a draft

需要电子邮件地址!它会从哪里返回?如果我正确的话。 - Naaz
我已经更新了答案,其中包含了使用此结果获取的所有数据及其描述。 - Ravindra Shekhawat
你的 PHPifo 上是否正确安装了 OpenSSL?其中包含以下值:OpenSSL 支持:已启用 OpenSSL 版本:OpenSSL 0.9.8g - Ravindra Shekhawat
我不知道我从未使用过PHP的OpenSSL,我最近是在Android中使用openssl,而且我正在使用我的在线Apache服务器与PHP,如何在其上安装openssl? - Naaz
1
它从未在我的系统上工作,因为我一直在我的Apache服务器在线托管系统上进行测试,并通过电子邮件询问他们是否安装了openSSL。他们告诉我是的,他们已经在服务器上安装了openSSL并且已经正确激活。 - Naaz
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接