【问题标题】:Fatal error: Call to undefined function imap_open()致命错误:调用未定义的函数 imap_open()
【发布时间】:2014-02-19 19:01:27
【问题描述】:

我正在尝试使用 php 阅读电子邮件,我正在使用以下代码,但它出现错误Fatal error: Call to undefined function imap_open() in /testpage2/testmail.php on line 18 任何人都可以指导我。谢谢

<?php
$codes = array("7bit","8bit","binary","base64","quoted-printable","other");
$stt = array("Text","Multipart","Message","Application","Audio","Image","Video","Other");

$pictures = 0;
$html = "";

# Connect to the mail server and grab headers from the mailbox

$mail = imap_open('{mail.xxxxxxxx.com:110/pop3}', 'xxxxxx@xxxxxxxx.com', 'xxxxxxxxx');
$headers = imap_headers($mail);

# loop through each email

for ($n=1; $n<=count($headers); $n++) {
        $html .=  "<h3>".$headers[$n-1]."</h3><br />";

# Read the email structure and decide if it's multipart or not

        $st = imap_fetchstructure($mail, $n);
        $multi = $st->parts;
        $nparts = count($multi);
        if ($nparts == 0) {
                $html .=  "* SINGLE part email<br>";
        } else{
                $html .=  "* MULTI part email<br>";
        }

# look at the main part of the email, and subparts if they're present

        for ($p=0; $p<=$nparts; $p++) {
                $text =imap_fetchbody($mail,$n,$p);
                if ($p ==  0) {
                        $it = $stt[$st->type];
                        $is = ucfirst(strtolower($st->subtype));
                        $ie = $codes[$st->encoding];
                } else {
                        $it = $stt[$multi[$p-1]->type];
                        $is = ucfirst(strtolower($multi[$p-1]->subtype));
                        $ie = $codes[$multi[$p-1]->encoding];
                }

# Report on the mimetype

                $mimetype = "$it/$is";
                $html .=  "<br /><b>Part $p ... ";
                $html .=  "Encoding: $ie for $mimetype</b><br />";

# decode content if it's encoded (more types to add later!)

                if ($ie == "base64") {
                        $realdata = imap_base64($text);
                        }
                if ($ie == "quoted-printable") {
                        $realdata = imap_qprint($text);
                        }

# If it's a .jpg image, save it (more types to add later)

                if ($mimetype == "Image/Jpeg") {
                        $picture++;
                        $fho = fopen("imx/mp$picture.jpg","w");
                        fputs($fho,$realdata);
                        fclose($fho);
                        # And put the image in the report, limited in size
                        $html .= "<img src=/demo/imx/mp$picture.jpg width=150><br />";
                }

# Add the start of the text to the message

                $shorttext = substr($text,0,800);
                if (strlen($text) > 800) $horttext .= " ...\n";
                $html .=  nl2br(htmlspecialchars($shorttext))."<br>";
        }
}

# report results ...

?>
<html>
<head>
<title>Reading a Mailbox including multipart emails from within PHP</title>
</head>
<body>
<h1>Mailbox Summary ....</h1>
<?= $html ?>
</body>
</html>

【问题讨论】:

标签: php email imap pop3


【解决方案1】:

你需要enable IMAP in PHP才能使用它。如果你做一个phpinfo()你可以确认它是否被安装。

【讨论】:

    【解决方案2】:

    您的服务器上没有安装用于 PHP 的 IMAP 模块。 安装php5-imap

    参考:http://www.php.net/manual/en/imap.setup.php

    【讨论】:

      【解决方案3】:

      检查天气 imap 是否在您的服务器中启用,如果未启用则表示启用它。如果未安装 imap 扩展意味着安装并启用它,请查看此链接 http://www.php.net/manual/en/imap.setup.php

      【讨论】:

        【解决方案4】:

        正如其他人所说,启用或安装 imap 扩展(例如 ubuntu/debian 中的 php5-imap)。顺便提一句。看看Fetch,它是一个很棒的面向 OOP 的库,用于处理 IMAP。

        【讨论】:

          【解决方案5】:

          如果您使用 XAMPP,请启用 php_imap.dll extension 去你的XAMPP/php 更改php.ini file

          ;extension=php_imap.dll
          

           extension=php_imap.dll
          

          【讨论】:

            【解决方案6】:

            如果您有php 7+,请更新您的php.ini 文件

            取消注释

            ;extension=imap

            extension=imap

            如果您找不到extension=imap,则手动将其添加到您的php.ini 到定义其他扩展的部分,只需搜索;extension

            最后重启 Apache

            【讨论】:

              猜你喜欢
              • 2020-08-08
              • 2012-03-28
              • 1970-01-01
              • 2017-09-03
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多