我正在处理我的代码,使用php获取和阅读我的电子邮件。当我给自己发送测试电子邮件时,我在阅读电子邮件时遇到了问题。我尝试这样做时无法将电子邮件读入text / html:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$imap = imap_open("{imap.mydomain.com:993/imap/ssl/novalidate-cert}INBOX", "[email protected]", "mypassword") or die("Can't connect: " . imap_last_error());
$message = imap_fetchbody($imap,217, 1);
$message = nl2br($message);
echo $message;
/* close the connection */
imap_close($imap);
?>
我也试过这个:
$message = imap_fetchbody($imap,217, 1.2);
当我尝试imap_fetchbody($imap,217, 1.2);
时,它不会在text / html中显示电子邮件,因此当我尝试使用imap_fetchbody($imap,217, 1)
时,它只会将电子邮件正文显示为普通/文本。我想用text / html阅读我的电子邮件,但我不知道该怎么做。
我已经检查了标题,它显示:Content-Type: multipart/alternative;
我正在使用pear mail imap库来阅读我的电子邮件。
你能告诉我一个例子,我怎么能用text / html阅读我的电子邮件,这样我才能看到超链接和HTML代码?
谢谢。
根据the documentation for the imap_fetchbody
function,部分论证是
由句点分隔的整数字符串,根据IMAP4规范索引到正文部分列表中
所以尝试将其作为字符串而不是浮点数传递:
$message = imap_fetchbody($imap,217, "1.2");