PHP IMAP扩展获取干净的消息体
我只是对PHP的IMAP扩展进行了一些试验,并使用如下对象构建了连接:PHP IMAP扩展获取干净的消息体,php,email,imap,Php,Email,Imap,我只是对PHP的IMAP扩展进行了一些试验,并使用如下对象构建了连接: function __construct($user, $pass, $server = 'my.mailserver.ch', $port = 143) { $this->server = $server; $this->user = $user; $this->pass = $pass; $this->port = $port; if($this->
function __construct($user, $pass, $server = 'my.mailserver.ch', $port = 143) {
$this->server = $server;
$this->user = $user;
$this->pass = $pass;
$this->port = $port;
if($this->conn = imap_open('{'.$this->server.'}', $this->user, $this->pass)){
$this->success = 1;
}else{
$this->success = -1;
}
$this->inbox();
}
然后,我使用以下函数从邮件中获取必要的数据。
(哪个有效)
等等。我检查了如何从“多部分/备选方案”中获得干净的身体,但找不到任何对我有帮助的方法。同样,在同一正文中也有几种不同的内容类型
我如何获得消息的干净正文,并且对于不同的内容类型,我必须以不同的方式处理它吗
感谢您的帮助。电子邮件解析本身就是一个完整的主题。如果你想知道关于电子邮件的一切,你需要一个MIME解析器。你也可以解释车身结构,试着找到正确的子部分并解码,在Stackoverflow上有几十个这样的例子。我会研究一下,非常感谢你的快速回答。
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_fetchbody($this->conn, $i),
'structure' => imap_fetchstructure($this->conn, $i)
);
}
$this->inbox = $in;
}
--001a113ec946082fc705210e59c7 Content-Type: multipart/alternative; boundary=001a113ec946082fc005210e59c5 --001a113ec946082fc005210e59c5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding