时间:2021-07-01 10:21:17 帮助过:10人阅读
\r\n";
}
}
function send($from,$to,$subject,$body)
{
if($from == "" || $to == "")
{
exit("请输入信箱地址");
}
if($subject == "") $sebject = "无标题";
if($body == "") $body = "无内容";
$All = "From:".$from."\r\n";
$All .= "To:".$to."\r\n";
$All .= "Subject:".$subject."\r\n";
if($this->mailformat==1) $All.= "Content-Type: text/html;\r\n";
else $All .= "Content-Type: text/plain;\r\n";
$All .= "charset=gb2312\r\n\r\n";
$All .= $body;
/*
如果把$All的内容再加处理,就可以实现发送MIME邮件了
不过还需要加很多程序
*/
//以下是和服务器会话
$this->in = "EHLO HELO\r\n";
$this->docommand();
$this->in = "AUTH LOGIN\r\n";
$this->docommand();
$this->in = $this->user."\r\n";
$this->docommand();
$this->in = $this->pass."\r\n";
$this->docommand();
if(!eregi("235",$this->result_str)){
$this->result_str = "smtp 认证失败";
$this->debug_show($this->result_str);
return 0;
}
$this->in = "MAIL FROM:".$from."\r\n";
$this->docommand();
$this->in = "RCPT TO:".$to."\r\n";
$this->docommand();
$this->in = "DATA\r\n";
$this->docommand();
$this->in = $All."\r\n.\r\n";
$this->docommand();
if(!eregi("250",$this->result_str)){
$this->result_str = "邮件发送失败";
$this->debug_show($this->result_str);
return 0;
}
$this->in = "QUIT\r\n";
$this->docommand();
//结束,关闭连接
return 1;
}
function docommand()
{
socket_write ($this->socket, $this->in, strlen ($this->in));
$this->debug_show("客户机命令:".$this->in);
$this->result_str = "服务器应答:".socket_read ($this->socket, 1024)."";
$this->debug_show($this->result_str);
}
} //end class
?>
先把文件内上面程序里的这些内容填进去,如:
var $ host="smtp.sina.com.cn"; //主机
var $port="25"; //端口 一般为25
var $user=" users"; //SMTP认证的帐号
var $pass="users123; //认证密码
然后把这个文件放到你网站下,只要你网站的程序访问的到就行,.
然后要用到发邮件的程序里包含进来 如: include('smtp.class.php');
然后在这个发邮件的程序里用
$mails=new smtp_mail();
if($mail->send("发信人地址","收信人邮箱地址","主题","内容")){
echo "发 送成功!";
}else{
echo "邮件服务器忙,请稍候再试试";
}