我正在使用以下代码在 PHP 中发送电子邮件:
<?php
error_reporting(E_ALL);
# write mail
###############################################################################
$recipient = "mail@server.tld";
$subject = mb_encode_mimeheader("Subject äöü ");
$text = "Hallo";
$header = "From:".mb_encode_mimeheader("Name with [], ÄÖÜ and spaces")." <webmaster@example.com>"
. "\r\n" . "Reply-To: webmaster@example.com"
. "\r\n" . "X-Mailer: PHP/" . phpversion();
// send e-mail
mail($recipient, $subject, $text, $header);
?>
imap_fetch_overview()
之后我尝试使用以下代码阅读电子邮件:
<?php
# receive mails
###############################################################################
$mailbox = imap_open("{imap.server.tld/norsh}", "mail@server.tld", "********");
$MC = imap_check($mailbox);
$result = imap_fetch_overview($mailbox,"1:{$MC->Nmsgs}",0);
echo "<table>";
foreach ($result as $overview) {
echo "<tr>"
."<td>".$overview->msgno."</td>"
."<td>".$overview->uid."</td>"
."<td>".$overview->date."</td>"
."<td>".$overview->udate."</td>"
."<td>".$overview->from."</td>"
."<td>".$overview->to."</td>"
."<td>".$overview->size."</td>"
."<td>".$overview->subject."</td>"
."</tr>";
}
echo "</table>";
?>
我收到以下错误:
Notice: Undefined property: stdClass::$from in /mail_test.php on line 34
而且$overview->from
没有价值。
当“From:”部分不包含括号时,没有问题。我还必须对括号进行编码吗?如何?我以为mb_encode_mimeheader()
正在做这项工作。
编辑:
结果var_dump($overview)
是:
object(stdClass)#18 (14) {
["subject"]=>
string(40) "Subject =?UTF-8?B?w4PCpMODwrzDg8K2IA==?="
["to"]=>
string(16) "mail@server.tld"
["date"]=>
string(31) "Thu, 16 Aug 2012 16:58:23 +0200"
["message_id"]=>
string(58) "<**************************************>"
["size"]=>
int(1585)
["uid"]=>
int(18)
["msgno"]=>
int(17)
["recent"]=>
int(1)
["flagged"]=>
int(0)
["answered"]=>
int(0)
["deleted"]=>
int(0)
["seen"]=>
int(0)
["draft"]=>
int(0)
["udate"]=>
int(1345129104)
}