Home > Backend Development > PHP Tutorial > 用PHP读取IMAP邮件_PHP

用PHP读取IMAP邮件_PHP

WBOY
Release: 2016-06-01 12:27:29
Original
866 people have browsed it

IMAP

//这个例子可以练习关于IMAP的函数
//但是如果真的要写WEBMAIL,那么要考虑的东西就不止这些了……孤狼

login.php3

if (!$PHP_AUTH_USER) {
Header("WWW-authenticate: basic realm="邮件客户检查"");
Header("HTTP/1.0 401 Unauthorized");
} else {
$MYDIR=ereg_replace("/[^/] $","",$PHP_SELF);
Header("Location: $SERVER_NAME$MYDIR/messages.php3");
}

?>

这个进行用户检查并将用户引导到用户邮件页.

messages.php3


$MAILSERVER="{localhost/imap}";
$link=imap_open($MAILSERVER,$PHP_AUTH_USER,$PHP_AUTH_PW);
$headers=imap_headers($link);

for($x=1; $x $idx=($x-1);
echo "$headers[$idx]
";
}

?>

通过验证后连接到IMAP服务器$MAILSERVER

然后在取得邮件列表,并创建阅读邮件的连接

view.php3:


$MAILSERVER="{localhost/imap}";
$link=imap_open($MAILSERVER,$PHP_AUTH_USER,$PHP_AUTH_PW);
$header=imap_header($link,$num);

echo "From: $header[fromaddress]
";
echo "To: $header[toaddress]
";
echo "Date: $header[Date]
";
echo "Subject: $header[Subject]

";
echo imap_body($link,$num);

?>

view.php3打开IMAP连接并取得邮件头部信息并显示

这Only是一个拿来完完的小程序,要完整的自己去写啦!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template