我想显示电子邮件的正文内容.我在php中尝试过IMAP但是有些东西是非常错误的. IMAP没有收集我的信息正文.它只能在身体中获取签名.所以我正在寻找将电子邮件正文内容读取到网页的替代方法.
这是我的电子邮件的原始文件:
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年的历史.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。