![](/img/trans.png)
[英]How to use IMAP function(s) in PHP to get the mail body content in HTML mode?
[英]How to use IMAP in PHP to fetch mail body content?
我无法获取电子邮件正文内容。
这是我的代码
<?php
/* connect to server */
$hostname = '{myserver/pop3/novalidate-cert}INBOX';
$username = 'username';
$password = 'password';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
//echo $inbox;
/* 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) {
//$email_number=$emails[0];
//print_r($emails);
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
当我用来从Gmail提取电子邮件时,会显示电子邮件正文内容,但是一旦我使用邮件服务器,便无法提取电子邮件的正文内容。
您能帮我解决这个问题吗?
我找到了解决方案,此行出现错误
$message = imap_fetchbody($inbox,$email_number,2);
现在,我正在使用
$message = imap_fetchbody($inbox,$email_number, 1.2);
接收text / html格式的正文内容
下面我给出了可用选项的数据。 这可能是一些
()Root Message Part (multipart/related)
(1) The text parts of the message (multipart/alternative)
(1.1) Plain text version (text/plain)
(1.2) HTML version (text/html)
(2) The background stationary (image/gif)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.