答案:<?php
if ($EMAIL_INC) return;
$EMAIL_INC= "defined";
define( "SmtpPort",25);
class Pop3 {
var $subject; // 邮件主题
var $from_email; // 发件人地址
var $from_name; // 发件人姓名
var $to_email; // 收件人地址
var $to_name; // 收件人姓名
var $body; // 邮件内容
var $filename; // 文件名
var $socket; // 当前的 socket
var $Line;
var $Status;
function pop3_open($server, $port)
{
$this->Socket = fsockopen($server, $port);
if ($this->Socket <= 0){
return false;
}
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return false;
return true;
}
function pop3_user($user)
{
if ($this->Socket < 0){
return false;
}
fputs($this->Socket, "USER $this->user\r\n");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return false;
return true;
}
function pop3_pass( $pass)
{
fputs($this->Socket, "PASS $pass\r\n");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return 0;
return 1;
}
function pop3_stat()
{
fputs($this->Socket, "STAT\r\n");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return 0;
if (!eregi( "+OK (.*) (.*)", $this->Line, $regs))
return 0;
return $regs[1];
}
function pop3_list()
{
fputs($this->Socket, "LIST\r\n");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return 0;
$i = 0;
while (substr($this->Line = fgets($this->Socket, 1024), 0, 1) <> ".")
{
$articles[$i] = $this->Line;
$i++;
}
$articles[ "count"] = $i;
return $articles;
}
function pop3_retr($nr)
{
fputs($this->Socket, "RETR $nr\r\n");
$this->Line = fgets($this->Socket, 1024);
$this->Status[ "LASTRESULT"] = substr($this->Line, 0, 1);
$this->Status[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "+") return 0;
while (substr($this->Line = &nbs
上一个:网上找到的两个PHP发送邮件的例子,很不错,贴出来给初学者参考吧(不知道是否有兄弟曾贴过),呵呵(2)
下一个:WINXp,windows2000下配置apache2.0.52+php5.0.2+mysql4.0