[原创] 用Socket发送电子邮件(利用需要验证发SMTP服务器)
小露珠 发表于 2003-9-18 17:46 PHP ←返回版面 [快速返回]
\r\n"; } } 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; /* 如过把$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(); $this->in = "MAIL FROM:".$this->from."\r\n"; $this->docommand(); $this->in = "RCPT TO:".$this->to."\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All."\r\n.\r\n"; $this->docommand(); $this->in = "QUIT\r\n"; $this->docommand(); //结束,关闭连接 } 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); } } //这个是我做的测试,我用的是smtp.163.com,那你的信箱也必须是163.com的,要不人家不让你发!! //你用这个类的时候你修改成你自己的信箱就可以了 $smtp = new smtp_mail("smtp.163.com","25","你的163.com的帐号","你的密码"); //如果你需要显示会话信息,请将上面的修改成 //$smtp = new smtp_mail("smtp.163.com","25","你的163.com的帐号","你的密码",true); $smtp->send("你的163.com的帐号@163.com","目标地址","你好","你好"); ?> * - 本贴最后修改时间:2003-9-18 17:52:50 修改者:erquan * - 修改原因:edit title 你最好打开“会话信息”,以便有问题时查找原因
```