获取与imap连接的链接

时间:2012-09-24 13:52:48

标签: php email imap

我通过此代码连接到我的Gmail帐户

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
        $username = 'myacount@gmail.com';
        $password = 'password';

        /* 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);
            $message = imap_fetchbody($inbox,$email_number,2);
            $message=strip_tags($message);
            /* output the email header information */
            $emai=split("<",$overview[0]->from );
            echo 'Lus ou pas : '.($overview[0]->seen ? 'lue' : 'Non Lue').'<br>';
            echo 'subject : '.$overview[0]->subject.'<br> ';
            //echo 'from : '.$overview[0]->from.'<br>';
            echo 'from : '.$emai[0].' + '.$emai[1].'<br>';
            echo 'date :  '.$overview[0]->date.'<br>';

            /* output the email body */
            echo 'Message '.rawurlencode(utf8_decode(rawurldecode($message))).'<br>';
            break;
          }

          echo "<br><br><br><hr><br><br>";

        }

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

在我的帐户中,我有一封她身上的电子邮件

http://www.test.com?id=4

但是当我执行我的脚本时,我将她放在浏览器中

Lus ou pas : Non Lue
subject : test
from : =?ISO-8859-1?Q?fai=E7al_name?= + myacount@hotmail.com>
date : Mon, 24 Sep 2012 13:39:11 +0000
Message %0D%0A%0D%0A%0D%0A%3D0A%3D%0D%0A%3D0A%3D%0D%0A%3D0A%3D%0D%0Ahttp%3A%2F%2Fwww.test.com%3Fid%3D3D4%20%09%09%20%09%20%20%20%09%09%20%20%20%09%09%20%09%20%20%20%3D%0D%0A%09%09%20%20%0D%0A%3D%0D%0A

如何准确地获取链接。

Ps:英语不是我的母语,对任何错误都感到抱歉。

2 个答案:

答案 0 :(得分:2)

<?php echo 'Message : '.quoted_printable_decode($message).'<br/>';

答案 1 :(得分:1)

试试这个:

$s = urldecode('%0D%0A%0D%0A%0D%0A%3D0A%3D%0D%0A%3D0A%3D%0D%0A%3D0A%3D%0D%0Ahttp%3A%2F%2Fwww.test.com%3Fid%3D3D4%20%09%09%20%09%20%20%20%09%09%20%20%20%09%09%20%09%20%20%20%3D%0D%0A%09%09%20%20%0D%0A%3D%0D%0A');
echo $s;

它会将=0A= =0A= =0A= http://www.test.com?id=3D4 = =输出到屏幕。

如果您不知道为什么您的邮件首先被urlencoded。但它适用于您的电子邮件客户端,因为电子邮件客户端会将邮件解码为。