【问题标题】:Email body did not displaying in html电子邮件正文未在 html 中显示
【发布时间】:2019-04-17 19:12:09
【问题描述】:

我正在编写代码以使用 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", "rob@mydomain.com", "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); 时,它不会以文本/html 显示电子邮件,所以当我尝试imap_fetchbody($imap,217, 1) 时,它只会将电子邮件正文显示为纯文本/文本。我想以 text/html 格式阅读我的电子邮件,但我不知道该怎么做。

我检查了标题,它显示:Content-Type: multipart/alternative;

我正在使用 pear mail imap 库来阅读我的电子邮件。

您能否给我展示一个示例,我如何能够阅读 text/html 格式的电子邮件,以便我能够看到超链接和 html 代码?

谢谢。

【问题讨论】:

    标签: php email html-email imap


    【解决方案1】:

    根据the documentation for the imap_fetchbody function,section 参数是

    由句点分隔的整数字符串,根据 IMAP4 规范索引到正文部分列表中

    所以尝试将其作为字符串而不是浮点数传递:

    $message = imap_fetchbody($imap,217, "1.2");
    

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 2013-12-16
      • 2019-12-14
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多