php – 如何向网站显示电子邮件的内容?
发布时间:2020-12-13 17:09:53 所属栏目:PHP教程 来源:网络整理
导读:我想显示电子邮件的正文内容.我在php中尝试过IMAP但是有些东西是非常错误的. IMAP没有收集我的信息正文.它只能在身体中获取签名.所以我正在寻找将电子邮件正文内容读取到网页的替代方法. 这是我的电子邮件的原始文件: http://pastebin.com/WQra335P IMAP正
我想显示电子邮件的正文内容.我在php中尝试过IMAP但是有些东西是非常错误的. IMAP没有收集我的信息正文.它只能在身体中获取签名.所以我正在寻找将电子邮件正文内容读取到网页的替代方法.
这是我的电子邮件的原始文件: http://pastebin.com/WQra335P IMAP正在抓取免责声明/版权模糊,但正在显示身体其他任何内容.有没有其他方法可以从gmail或任何其他可以将内容显示到网页的网站上阅读电子邮件? 我已经放弃了让IMAP阅读它,因为没有人能够找出问题…我已经花了好几个小时所以我放弃但这里是代码…… <?php /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'username@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,2); echo $message; echo imap_qprint($message); $message = imap_qprint($message); echo imap_8bit ($message); $DateFormatted = str_replace("-0500","",$overview[0] -> date); /* output the email header information */ $output .= $overview[0] -> subject ; $output .= $DateFormatted ; //$bodyFormatted = preg_replace("/This e-mail(.*)/",$message); //$bodyFormatted = preg_replace("/Ce courriel(.*)/",$bodyFormatted); /* output the email body */ $output .= $message; } echo $output; } /* close the connection */ imap_close($inbox); ?> 解决方法
除了DmitryK建议的,
添加以下内容使得一切正常,没有随机的“=”符号. Str_replace用于删除页面上生成的“=”. $message = imap_fetchbody($inbox,"1.1"); $message = str_replace("=",$message); 我不知道100%为什么随机生成“=”,但这很可能是由于Exchange Server的一些加密问题,因为我们的服务器大约有10年的历史. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |