用PHP发送电子邮件示例程序
时间:2006-07-25 来源:linxh
host=$h;
$this->port=$port;
$this->user=base64_encode($u);
$this->pass=base64_encode($pass);
$this->debug=$d;
}
function debug_show($str)
{
if($this->debug) {
echo $str."
\n";
}
}
function docomm()
{
fputs($this->fp,$this->comm);
$this->debug_show("Command from Client:\n".$this->comm);
$this->result=fgets($this->fp,1024);
$this->debug_show("Response from Server:\n".$this->result);
}
function send($f,$t,$s,$b)
{
if($f==""||$t=="") {
exit("Please input the E-mail Address");
}
if($s=="") $s="[No Subject]";
if($b=="") $b="[No Content]";
$this->from=$f;
$this->to=$t;
$this->subject=$s;
$this->body=$b;
$q="Subject: ".$this->subject."\n";
/*$q.="From: ".$this->from."\n";*/
$q.="To: ".$this->to."\n\n";
$q.=$this->body;
$this->fp=fsockopen ($this->host, $this->port);
if(!$this->fp) {
exit("Error opening socket");
}
set_socket_blocking($this->fp, true );
$this->result=fgets($this->fp,1024);
$this->debug_show($this->result);
if(!ereg("^220",$this->result)) {
exit("Server Respose error");
}
$this->comm="HELO php_test\n";
$this->docomm();
$this->comm="AUTH LOGIN\n";
$this->docomm();
$this->comm=$this->user."\n";
$this->docomm();
/* $this->comm="AUTH LOGIN ".$this->user."\n";
$this->docomm();
*/
$this->comm=$this->pass."\n";
$this->docomm();
$this->comm="MAIL FROM:from.">\n";
$this->docomm();
$this->comm="RCPT TO:to.">\n";
$this->docomm();
$this->comm="DATA\n";
$this->docomm();
$this->comm=$q."\n.\n";
$this->docomm();
$this->comm="QUIT\n";
$this->docomm();
}
}
$test= new smtp_mail("smtp.126.com","25","***","*******",false);
$test->send("*****","***","*******","*******");
print "";
print "您添写的信息,已经被发送到"."*******"."了";
print "";
?>
相关阅读 更多 +