php - 是否有 php imap 扩展的替代方案

标签 php imap

我的 godaddy 共享 hosing 服务不会为 PHP 启用 IMAP 扩展。所以我在泡菜:

是否有 PHP 函数来替代 PHP 中的 IMAP 功能?

这里是错误:

Fatal error: Call to undefined function imap_last_error()

这是我遇到问题的示例代码:

$mbox = imap_open ('{'.$email_host.':'.$email_port.'/pop3/novalidate-cert}INBOX', $email_username, $email_password) or die(imap_last_error());



        if(!$mbox){
            // send email letting them know bounce checking failed?
            // meh. later.
            echo 'Failed to connect when checking bounces.';
        }else{
            $MC = imap_check($mbox);
            $result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
            foreach ($result as $overview) {
                $this_subject = (string)$overview->subject;
                //echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from} <br> {$this_subject} <br>\n";
                $tmp_file = tempnam('/tmp/','newsletter_bounce');
                // TODO - tmp files for windows hosting.
                imap_savebody  ($mbox, $tmp_file, $overview->msgno);
                $body = file_get_contents($tmp_file);
                if(preg_match('/Message-ID:\s*<?Newsletter-(\d+)-(\d+)-([A-Fa-f0-9]{32})/imsU',$body,$matches)){
                    // we have a newsletter message id, check the hash and mark a bounce.
                    //"message_id" => "Newsletter-$send_id-$member_id-".md5("bounce check for $member_id in send $send_id"),
                    $send_id = (int)$matches[1];
                    $member_id = (int)$matches[2];
                    $provided_hash = trim($matches[3]);
                    $real_hash = md5("bounce check for $member_id in send $send_id");
                    if($provided_hash == $real_hash){
                        $sql = "UPDATE "._DB_PREFIX."newsletter_member SET `status` = 4, bounce_time = '".time()."' WHERE `member_id` = '".$member_id."' AND send_id = '".$send_id."' AND `status` = 3 LIMIT 1";
                        query($sql);
                        imap_delete($mbox, $overview->msgno);
                    }else{
                        // bad hash, report.
                    }
                }
                unlink($tmp_file);
            }
            imap_expunge($mbox);
            imap_close($mbox);
        }

    }

提前致谢!

最佳答案

这个适用于 godaddy 共享主机: http://www.phpclasses.org/package/4014-PHP-Retrieve-and-delete-messages-from-a-POP3-mailbox.html

这一个也有效:http://framework.zend.com/manual/1.12/en/zend.mail.html

function __autoload($class_name) {
include $class_name . '.php';
}
 include_once 'Zend/Mail/Storage/AbstractStorage.php';
include_once 'Zend/Mail/Storage/Pop3.php';
$mail = new Zend\Mail\Storage\Pop3(array('host'     => '$host',
                                     'user'     => '$user',
                                     'password' => '$password'));

echo $mail->countMessages() . " messages found\n";
foreach ($mail as $message) {
   echo "Mail from '{$message->from}': {$message->subject}\n</br>";
   echo $message->getContent() . "</br>";
}

关于php - 是否有 php imap 扩展的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13483119/

相关文章:

php - 具有 PSR-4 自动加载功能的 Composer : classes from namespace not loading

php - 检查 MySQL 中单行字符串中是否存在数字

php - laravel eloquent 删除以零结尾的整数的最后一个零

php - 如何编写将纯文本转换为可点击链接的函数,其中文本包含 5 种类型的 URL

javascript - imap.search 时 Node.js imap 库中出现错误协议(protocol)错误

c# - 我如何清除 IEnumerable<ImapX.Messages>?

php - Magento,将产品名称传递给联系表

ruby-on-rails - 通过 IMAP 在 Rails 中获取电子邮件

go - 如何获取 IMAP 消息的可见/不可见状态

php - 使用 PHP 连接到 IMAP