doudou890510 2013-09-28 03:59
浏览 51
已采纳

为什么我不能回复imap标题主题行? PHP

Using the following class:

class Email_reader {

        // imap server connection
        public $conn;

        // inbox storage and inbox message count
        private $inbox;
        private $msg_cnt;

        // email login credentials
        private $server = 'xxxxxxxxxxxx.com';
        private $user   = 'admin@xxxxxxxxx.com';
        private $pass   = 'xxxxxxxxx';
        private $port   = 143; // adjust according to server settings

        // connect to the server and get the inbox emails
        function __construct() {
            $this->connect();
            $this->inbox();
        }

        // close the server connection
        function close() {
            $this->inbox = array();
            $this->msg_cnt = 0;

            imap_close($this->conn);
        }

        // open the server connection
        // the imap_open function parameters will need to be changed for the particular server
        // these are laid out to connect to a Dreamhost IMAP server
        function connect() {
            $this->conn = imap_open('{'.$this->server.'/notls}', $this->user, $this->pass);
        }

        // move the message to a new folder
        function move($msg_index, $folder='INBOX.Processed') {
            // move on server
            imap_mail_move($this->conn, $msg_index, $folder);
            imap_expunge($this->conn);

            // re-read the inbox
            $this->inbox();
        }

        // get a specific message (1 = first email, 2 = second email, etc.)
        function get($msg_index=NULL) {
            if (count($this->inbox) <= 0) {
                return array();
            }
            elseif ( ! is_null($msg_index) && isset($this->inbox[$msg_index])) {
                return $this->inbox[$msg_index];
            }

            return $this->inbox[0];
        }

        // read the inbox
        function inbox() {
            $this->msg_cnt = imap_num_msg($this->conn);

            $in = array();
            for($i = 1; $i <= $this->msg_cnt; $i++) {
                $in[] = array(
                    'index'     => $i,
                    'header'    => imap_headerinfo($this->conn, $i),
                    'body'      => imap_body($this->conn, $i),
                    'structure' => imap_fetchstructure($this->conn, $i)
                );
            }

            $this->inbox = $in;
        }

    }

And the following usage code:

$email = new Email_reader();
$msg = $email->get(1);
echo "message body is [".$msg['body']."]<br />"; //prints body //good
echo "message index is [".$msg['index']."]<br />"; //prints "2" //good
echo "message subject is [".$msg['header']->Subject."]<br />"; //prints strangness
echo "message toaddress is [".$msg['header']->toaddress."]<br />"; //prints strangeness

the attempt to print subject line prints "=?utf-8?B?TWljcm9zb2Z0IE9mZmljZSBPdXRsb29rIFRlc3QgTWVzc2FnZQ==?=" and the toaddress also something similar.

I looked at some other examples online but i dont see anything different that they do than what im doing.

  • 写回答

1条回答 默认 最新

  • dsmlf1207915 2013-09-30 14:06
    关注

    You have to decode the RFC 2047 encoding of the Unicode data. Check the imap_utf8 function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c