s[ "LASTRESULTTXT"] = substr($this->Line, 0, 1024);
if ($this->Status[ "LASTRESULT"] <> "2") return false;
return true;
}
function MailFrom($FromEmail)
{
if (fputs($this->Socket, "MAIL FROM: <$FromEmail>rn")<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"] <> "2") return false;
return true;
}
function RcptTo($ToEmail)
{
if(fputs($this->Socket, "RCPT TO: <$ToEmail>rn")<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"] <> "2") return false;
return true;
}
function Body()
{
$FileSize = 0;
$Attachment = null;
$fp = null;
$buffer = sprintf( "From: %srnTo:%srnSubject:%srn", $this->FromName, $this->ToName, $this->Subject);
if(fputs($this->Socket, "DATArn")<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"] <> "3") return false;
if(fputs($this->Socket, $buffer)<0){
return false;
}
if ($this->Attachment == null){
if(fputs($this->Socket, "MIME-Version: 1.0rnContent-Type: text/plain; charset=ISO-8859-1rnContent-Transfer-Encoding: 7bitrnrn")<0){
return false;
}
if(fputs($this->Socket, "$this->Bodyrnrn")<0){
return false;
}
if(fputs($this->Socket, ".rn")<0){
return false;
}
$this->
POP3、SMTP邮件收发
程序 发表时间: 2001年09月28日 阅读次数: 18 推荐给朋友 打印本页
<?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->userrn");
$this->Line = fg