[英]mail reading in php with imap
i have read the mail in php with imap_fetchbody() and decode it with imap_qprint(). 我已经使用imap_fetchbody()阅读了php中的邮件,并使用imap_qprint()对其进行了解码。
$body = imap_fetchbody($mbox, $no, 1);
$body = imap_qprint($body);
but there is difference between original mail and output mail 但是原始邮件和输出邮件之间有区别
Original mail: 原始邮件:
Plain Text
纯文本
This is a testing mail to check
这是一封要检查的测试邮件
first second third fourth fifth sixth Home
第一第二第三第四第五第六
this is yellow background
这是黄色背景
website: http://bizved.com
网站: http : //bizved.com
testing of quote
报价测试
Thank you Hiren Manek Bhuved Solutions
谢谢Hiren Manek Bhuved解决方案
output mail 输出邮件
Plain Text
纯文本
This is a testing mail to check
这是一封要检查的测试邮件
first second third fourth fifth sixth Home
第一第二第三第四第五第六
this is yellow background
这是黄色背景
website: http://bizved.com
网址:http://bizved.com
testing of quote
报价测试
Thank you Hiren Manek Bhuved Solutions
谢谢... Hiren Manek Bhuved解决方案
can anybody gives solution? 有人可以解决吗? thanks in advance.
提前致谢。
I always had the same problem with imaps. 我对imaps总是有同样的问题。 I'dont guarantee for anything but you may want to give this a try:
我不保证任何事情,但是您可以尝试一下:
function utf8_imap_header_decode($str)
{
$tmp = imap_mime_header_decode($str);
if (!mb_check_encoding($tmp[0]->text, 'UTF-8'))
return utf8_encode($tmp[0]->text);
return $tmp[0]->text;
}
function utf8_imap_body_decode($str)
{
return utf8_encode(quoted_printable_decode($str));
}
I have make the following solution as mail headers already its character set. 我已经做了以下解决方案,因为邮件头已经是它的字符集了。
$st = imap_fetchstructure($mbox, $no);
$part = $st->parts[$partno];
$body = imap_fetchbody($mbox, $no, $partno);
$body = imap_qprint($body);
$charset = 'UTF-8';
if(!empty($part->parameters)){
for ($k = 0, $l = count($part->parameters); $k < $l; $k++) {
$attribute = $part->parameters[$k];
if($attribute->attribute == 'CHARSET'){
$charset = $attribute->value;
}
}
}
//echo $charset;
$bodytext = mb_convert_encoding($body,'UTF-8',$charset);
This not full solution. 这不是完整的解决方案。 It's only for character encoding.
仅用于字符编码。 Mail has different parts for plain text, html text, attachments, etc. for that you should have different handling for each type.
邮件对于纯文本,html文本,附件等具有不同的部分,因此您应对每种类型进行不同的处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.