如果您无法访问imap_*函数,并且不想使用
?$message = chunk_split( base64_encode($message) );?
因为您希望能够阅读邮件的“源代码”,您可能想尝试这个方法
(非常欢迎任何建议!)
function qp_enc($input = "quoted-printable encoding test string", $line_max = 76) {
$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
$lines = preg_split("/(?:\r\n|\r|\n)/", $input);
$eol = "\r\n";
$escape = "=";
$output = "";
while( list(, $line) = each($lines) ) {
//$line = rtrim($line); // 删除尾随空格 -> 不需要 =20\r\n
$linlen = strlen($line);
$newline = "";
for($i = 0; $i < $linlen; $i++) {
$c = substr($line, $i, 1);
$dec = ord($c);
if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // 只转换行尾的空格
$c = "=20";
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // 始终编码“\t”,这其实并非必需
$h2 = floor($dec/16); $h1 = floor($dec%16);
$c = $escape.$hex["$h2"].$hex["$h1"];
}
if ( (strlen($newline) + strlen($c)) >= $line_max ) { // 不计算CRLF
$output .= $newline.$escape.$eol; // 软换行;“ =\r\n”是可以的
$newline = "";
}
$newline .= $c;
} // for循环结束
$output .= $newline.$eol;
}
return trim($output);
}
$eight_bit = "\xA7 \xC4 \xD6 \xDC \xE4 \xF6 \xFC \xDF = xxx yyy zzz \r\n"
." \xA7 \r \xC4 \n \xD6 \x09 ";
print $eight_bit."\r\n---------------\r\n";
$encoded = qp_enc($eight_bit);
print $encoded;