-
- set_time_limit(120);
- class smtp_mail
- {
- var $host;
- var $port;
- var $user;
- var $pass;
- var $debug = false;
- var $conn;
- var $result_str;
- var $in;
- var $from;
- var $to;
- var $subject;
- var $body;
- function smtp_mail($host,$port,$user,$pass,$debug=false)
- {
- $this->host = $host;
- $this->port = $port;
- $this->user = base64_encode($user);
- $this->pass = base64_encode($pass);
- $this->debug = $debug;
- $this->socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);
- if($this->socket)
- {
- $this->result_str = "创建socket:".socket_strerror(socket_last_error());
- $this->debug_show($this->result_str);
- }
- else
- {
- exit("初始化失败,请检查您的网络连接和参数");
- }
- $this->conn = socket_connect($this->socket,$this->host,$this->port);
- if($this->conn)
- {
- $this->result_str = "创建socket连接:".socket_strerror(socket_last_error());
- $this->debug_show($this->result_str);
- }
- else
- {
- exit("初始化失败,请检查您的网络连接和参数");
- }
- $this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
- $this->debug_show($this->result_str);
-
- }
- function debug_show($str)
- {
- if($this->debug)
- {
- echo $str."<p>rn";
- }
- }
- function send($from,$to,$subject,$body)
- {
- if($from == "" || $to == "")
- {
- exit("请输入信箱地址");
- }
- if($subject == "") $sebject = "无标题";
- if($body == "") $body = "无内容";
- $this->from = $from;
- $this->to = $to;
- $this->subject = $subject;
- $this->body = $body;
- $all = "from:".$this->from."n";
- $all .= "to:".$this->to."n";
- $all .= "subject:".$this->subject."n";
- $all .= $this->body;
-
-
-
-
-
-
- $this->in = "ehlo helorn";
- $this->docommand();
- $this->in = "auth loginrn";
- $this->docommand();
- $this->in = $this->user."rn";
- $this->docommand();
- $this->in = $this->pass."rn";
- $this->docommand();
- $this->in = "mail from:".$this->from."rn";
- $this->docommand();
- $this->in = "rcpt to:".$this->to."rn";
- $this->docommand();
- $this->in = "datarn";
- $this->docommand();
- $this->in = $all."rn.rn";
- $this->docommand();
- $this->in = "quitrn";
- $this->docommand();
-
-
- }
- function docommand()
- {
- socket_write ($this->socket, $this->in, strlen ($this->in));
- $this->debug_show("客户机命令:".$this->in);
- $this->result_str = "服务器应答:<font color=#cc0000>".socket_read ($this->socket, 1024)."</font>";
- $this->debug_show($this->result_str);
- }
- }
-
-
- $smtp = new smtp_mail("smtp.163.com","25","t_design","000000",true);
-
-
- $smtp->send("t_design@163.com","t_beijing@yahoo.com.cn","你好","你好");
- ?>
(责任编辑:admin) |