【发布时间】:2012-01-11 19:05:51
【问题描述】:
我想显示电子邮件的正文内容。我在 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, $email_number, 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);
?>
【问题讨论】:
-
你能贴出你尝试过的
IMAP代码吗?