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

radish 2000-02-01 01:00:00
加精
...全文
372 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,您能再试试吗
电子邮件系统使用J2EE 邮件系统: 该项目涉及邮件系统。 该邮件系统项目具有不同的模块示例,例如,新用户从gmail以注册表单的形式创建我们的帐户,并且现有用户可以登录到名为该邮件系统的表单作为登录名。 电子邮件系统(或Intranet邮件)已被私有化,并且以Hotmail之类的不同形式存在。 免费邮件。 主要是网络邮件该项目将提供一种简便的方法来使用您的gmail创建新帐户并免费回复,转发,删除,接收和发送邮件。 目的:- 该项目旨在开发一个基于Web的邮件系统,用户可以通过以(MTA)邮件传输的形式发送邮件以及以IAMP,SMTP,POP作为邮件传递代理来发送和接收邮件。 需要该退出用户来验证其身份,然后他们才可以检查其邮箱的邮件。 他们也可以发送邮件。 整理文件夹的邮件,并可以从邮箱删除必要的邮件。 提供了良好的用户界面,可轻松执行所有这些任务。

21,886

社区成员

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

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