设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1000|回复: 3
打印 上一主题 下一主题

吴天明版主!!这是你写的吗?

[复制链接]
跳转到指定楼层
1#
发表于 2002-9-25 01:38:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
require("smtp.php");



$smtp=new smtp_class;
$smtp->host_name="mail.xiaocui.com";
$smtp->localhost="localhost";
$from="webmaster@xiaocui.com";
$to="root@xiaocui.com";
if($smtp->SendMessage(
$from,
array(
$to
),
array(
"From: $from",
"To: $to",
"Subject: Testing Manuel Lemos" SMTP class"
),
"Hello $to,\n\nIt is just to let you know that your SMTP class is working just fine.\n\nBye.\n"))
echo "Message sent to $to OK.\n";
else
echo "Cound not send the message to $to.\nError: ".$smtp->error."\n"
?>



smtp.php




class smtp_class
{
var $host_name="";
var $host_port=25;
var $localhost="";
var $timeout=0;
var $error="";
var $debug=1;
var $esmtp=1;
var $esmtp_host="";
var $esmtp_extensions=array();
var $maximum_piped_recipients=100;



/* private variables - DO NOT ACCESS */



var $state="Disconnected";
var $connection=0;
var $pending_recipients=0;



/* Private methods - DO NOT CALL */



Function OutputDebug($message)
{
echo $message,"
\n";
}



Function GetLine()
{
for($line="";;)
{
if(feof($this->connection))
{
$this->error="reached the end of stream while reading from socket";
return(0);
}
if(($data=fgets($this->connection,100))==false)
{
$this->error="it was not possible to read line from socket";
return(0);
}
$line.=$data;
$length=strlen($line);
if($length>=2
&& substr($line,$length-2,2)=="\r\n")
{
$line=substr($line,0,$length-2);
if($this->debug)
$this->OutputDebug("< $line");
return($line);
}
}
}



Function PutLine($line)
{
if($this->debug)
$this->OutputDebug("> $line");
if(!fputs($this->connection,"$line\r\n"))
{
$this->error="it was not possible to write line to socket";
return(0);
}
return(1);
}



Function PutData($data)
{
if(strlen($data))
{
if($this->debug)
$this->OutputDebug("> $data");
if(!fputs($this->connection,$data))
{
$this->error="it was not possible to write data to socket";
return(0);
}
}
return(1);
}



Function VerifyResultLines($code,$responses="")
{
if(GetType($responses)!="array")
$responses=array();
Unset($match_code);



while(($line=$this->GetLine($this->connection)))
{
if(IsSet($match_code))
{
if(strcmp(strtok($line," -"),$match_code))
{
$this->error=$line;
return(0);
}
}
else
{
$match_code=strtok($line," -");
if(GetType($code)=="array")
{
for($codes=0;$codes if($codes>=count($code))
{
$this->error=$line;
return(0);
}
}
else
{
if(strcmp($match_code,$code))
{
$this->error=$line;
return(0);
}
}
}
$responses[]=strtok("");
if(!strcmp($match_code,strtok($line," ")))
return(1);
}
return(-1);
}



Function FlushRecipients()
{
if($this->pending_sender)
{
if($this->VerifyResultLines("250")<=0)
return(0);
$this->pending_sender=0;
}
for(;$this->pending_recipients;$this->pending_recipients--)
{
if($this->VerifyResultLines(array("250","251"))<=0)
return(0);
}
return(1);
}



/* Public methods */



Function Connect()
{
$this->error=$error="";
$this->esmtp_host="";
$this->esmtp_extensions=array();
if(!($this->connection=($this->timeout ? fsockopen($this->host_name,$this->host_port,&$errno,&$error,$this->timeout) : fsockopen($this->host_name,$this->host_port))))
{
switch($error)
{
case -3:
$this->error="-3 socket could not be created";
return(0);
case -4:
$this->error="-4 dns lookup on hostname \"".$host_name."\" failed";
return(0);
case -5:
$this->error="-5 connection refused or timed out";
return(0);
case -6:
$this->error="-6 fdopen() call failed";
return(0);
case -7:
$this->error="-7 setvbuf() call failed";
return(0);
default:
$this->error=$error." could not connect to the host \"".$this->host_name."\"";
return(0);
}
}
else
{
if(!strcmp($localhost=$this->localhost,"")
&& !strcmp($localhost=getenv("SERVER_NAME"),"")
&& !strcmp($localhost=getenv("HOST"),""))
$localhost="localhost";
$success=0;
if($this->VerifyResultLines("220")>0)
{
if($this->esmtp)
{
$responses=array();
if($this->utLine("EHLO $localhost")
&& $this->VerifyResultLines("250",&$responses)>0)
{
$this->e
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2002-9-25 01:43:00 | 只看该作者
不不!!
我可写不了!
smtp发邮件  
--------------------------------------------------------------------------------
源作者:小白                   人气:380  
这是她写的!!
希望这个源程对你有用!
3#
发表于 2002-9-25 03:06:00 | 只看该作者
很多人都是調用完mail(),就OK了,但如果sendmail不是localhost,這個就發揮重大作用了。
好東西,經品呀,多謝吳老師!
4#
发表于 2002-9-25 17:43:00 | 只看该作者
不用谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-15 19:27 , Processed in 0.080093 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表