谁能给我一个PHP通过IAMP读/写信箱中信件的例子

radish 2000-02-01 01:00:00
加精
...全文
374 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
DOU 2000-02-02
  • 打赏
  • 举报
回复
转载
IMAP Mail Reading With PHP3

Mark Musone

Don't you hate it when you are at a friend's house or visiting relatives and you want to check your email but dont know your POP/IMAP settings. Or even worse, they dont have your POP or IMAP software?

Web based email seems to be the talk of the Net lately. Heres how to use PHP to make a quick, simple and effective IMAP or POP mail reader. Once this is done, you can now be able to read your email from anywhere in the world with only a web browser.

The first necessity is to make sure that you have an available IMAP server. you can get the UW imap server and libraries from ftp://ftp.cac.washington.edu/imap/ (you will need the libraries to compile into php anyway, so you might as well install the IMAP server that comes with it also)

Once you have a running IMAP server and PHP compiled with IMAP support (make sure you read the PHP docs on how to compile PHP with imap), the rest is easy!

We'll make a nice and simple 3-script based mail reader.

The first script will be to read in your IMAP username and password. We will use the standard PHP authentication for that.

login.php3 contains:

<?php

if (!$PHP_AUTH_USER) {
Header( "WWW-authenticate: basic realm=\"Mail Chek\"");
Header( "HTTP/1.0 401 Unauthorized");
} else {
$MYDIR=ereg_replace( "/[^/]+$", "",$PHP_SELF);
Header( "Location: $SERVER_NAME$MYDIR/messages.php3");
}

?>

This simply reads in your username and password and redirects you to the read mail reading page.

messages.php3 contains:

<?php

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

for($x=1; $x < count($headers); $x++) {
$idx=($x-1);
echo "<a href=\"view.php3?num=$x\">$headers[$idx]</a><br>";
}

?>

It opens up an IMAP connection to the mailserver specified by $MAILSERVER, passing in your username and password.

It then get a list of all the messgae headers and in a loop, prints them all out. Besides printing them out, it also makes each one a link to view.php3, passing it that message number.

view.php3 contains:

<?php

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

echo "From: $header[fromaddress]<br>";
echo "To: $header[toaddress]<br>";
echo "Date: $header[Date]<br>";
echo "Subject: $header[Subject]<br><br>";
echo imap_body($link,$num);

?>

view.php3 opens up the IMAP connection the same as above, and gets the mail message's header information and prints it out.

It then reads in the body of the mail message and prints that out to the screen.

Thats it! You now have a functional web based mail reader...Hotmail watch out, here comes php! ;^)
DOU 2000-02-02
  • 打赏
  • 举报
回复
http://web.horde.org/上有一个IMAP webmail client,它遵从GPL. 你可下载代码研究
我学习PHP时间不长,这个应用我也没研究过,以后还要多向你请教!
radish 2000-02-02
  • 打赏
  • 举报
回复
谢谢了,不过此方法不能读带附件的EMAIL,您能再试试吗

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧