001 <?php
002
003 /*请尊重别人的劳动成功,请保留此版权信息,谢谢!
004 作者:小露珠3.3
005 扬帆修正一点东西:在代码中已经用注释注明,本代码现在向qq发信没问题~
006 */
007 set_time_limit(120);
008 class smtp_mail
009 {
010 var $host; //主机
011 var $port; //端口 一般为25
012 var $user; //SMTP认证的帐号
013 var $pass; //认证密码
014 var $debug = false; //是否显示和服务器会话信息?
015 var $conn;
016 var $result_str; //结果 wifi共享
017 var $in; //客户机发送的命令
018 var $from; //源信箱
019 var $to; //目标信箱
020 var $subject; //主题
021 var $body; //内容
022 function smtp_mail($host,$port,$user,$pass,$debug=false)
023 {
024 $this->host = $host;
025 $this->port = $port;
026 $this->user = base64_encode($user);
027 $this->pass = base64_encode($pass);
028 $this->debug = $debug;
029 $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); //具体用法请参考手册
030 if($this->socket)
031 {
skype怎么用032 $this->result_str = "创建SOCKET:".socket_strerror(socket_last_error());
033 $this->debug_show($this->result_str);
034 }
035 else
036 {
037 exit("初始化失败,请检查您的网络连接和参数");
038 }
039 $this->conn = socket_connect($this->socket,$this->host,$this->port);
040 if($this->conn)
041 {
042 $this->result_str = "创建SOCKET连接:".socket_strerror(socket_last_error());
043 $this->debug_show($this->result_str);
044 }
045 else
046 {
047 exit("初始化失败,请检查您的网络连接和参数");
048 }
049 $this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
050 $this->debug_show($this->result_str);
什么牌子眼霜好用051
052
053 }
054 function debug_show($str)
火焰纹章封印之剑055 {
056 if($this->debug)
057 {
058 echo $str."<p>\r\n";
059 }
060 }
061 function send($from,$to,$subject,$body)
062 {
063 if($from == "" || $to == "")
064 {
065 exit("请输入信箱地址");
066 }
067 if($subject == "") $sebject = "无标题";
068 if($body == "") $body = "无内容";
069 $this->from = $from;
070 $this->to = $to;
071 $this->subject = $subject;
072 $this->body = $body;
073
074 //扬帆修改部分代码
075 $All = "From:<".$this->from.">\r\n";
076 $All .= "To:<".$this->to.">\r\n";
077 $All .= "Subject:".$this->subject."\r\n\r\n";
078 $All .= $this->body;
079 /*
080 如过把$All的内容再加处理,就可以实现发送MIME邮件了
081 不过还需要加很多程序
082 */
083
084
085 //以下是和服务器会话
086 $this->in = "EHLO HELO\r\n";
087 $this->docommand();
088
089 $this->in = "AUTH LOGIN\r\n";
090 $this->docommand();
091
092 $this->in = $this->user."\r\n";
093 $this->docommand();
094
095 $this->in = $this->pass."\r\n";
096 $this->docommand();
097
098 // $this->in = "MAIL FROM:".$this->from."\r\n";
099 $this->in = "MAIL FROM:<".$this->from.">\r\n"; //扬帆修改
泡萝卜条
100 $this->docommand();
101
102 // $this->in = "RCPT TO:".$this->to."\r\n";
103 $this->in = "RCPT TO:<".$this->to.">\r\n"; //扬帆修改
104 $this->docommand();
105
106 $this->in = "DATA\r\n";
107 $this->docommand();
108
109 $this->in = $All."\r\n.\r\n";
110 $this->docommand();
111
112 $this->in = "QUIT\r\n";
113 $this->docommand();
114
115 //结束,关闭连接
116
117
118
119 }
120 function docommand()
121 {
122 socket_write ($this->socket, $this->in, strlen ($this->in));
123 $this->debug_show("客户机命令:".$this->in);
124 $this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
125 $this->debug_show($this->result_str);
凤旭与锦觅双修有几次126 }
127 }
128 ?>
[代码] php代码
view sourceprint?01 <?php
02 //测试页面
03 include "smtp_mail.php";
04
05 //你用这个类的时候你修改成你自己的信箱就可以了
06 $smtp=new smtp_mail("smtp.qq","25","yourmail@qq","Your password",true);
07 //如果你需要显示会话信息,请将上面的修改成
08 //$smtp = new smtp_mail("smtp.qq","25","你的qq的帐号","你的密码",true);
09 $smtp->send("yourmail@qq","yourmail@qq","你好","测试邮件");
10 ?>
发布评论