socket 发送邮件
发布:smiling 来源: PHP粉丝网 添加日期:2014-01-20 12:15:14 浏览: 评论:0
- //原代码如下:
- set_time_limit(120);
- class smtp_mail
- {
- var $host; //主机
- var $port; //端口 一般为25
- var $user; //smtp认证的帐号
- 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;
- /*
- 如过把$all的内容再加处理,就可以实现发送mime邮件了
- 不过还需要加很多程序
- */
- //以下是和服务器会话
- $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.163.com,那你的信箱也必须是163.com的,要不人家不让你发!!
- //你用这个类的时候你修改成你自己的信箱就可以了
- $smtp = new smtp_mail("smtp.163.com","25","t_design","000000",true);
- //如果你需要显示会话信息,请将上面的修改成
- //$smtp = new smtp_mail("smtp.163.com","25","你的163.com的帐号","你的密码",true);
- $smtp->send("t_design@163.com","t_beijing@yahoo.com.cn","你好","你好");
- ?>
Tags: socket 发送邮件
相关文章
- ·php自定义类fsocket模拟post或get请求的方法(2021-06-15)
- ·PHP多功能图片处理类(2013-11-11)
- ·PHP 生成缩略图的类(2013-11-13)
- ·新手写的分页类(2013-11-13)
- ·一个分页显示类(2013-11-13)
- ·分享的一个分页类(2013-11-13)
- ·简单的php分页类(2013-11-14)
- ·我的 DataBase类(2013-11-28)
- ·一个功能比较高的分页类(for PHP5.x)(2013-11-28)
- ·PHP Spreadsheet_Excel_Reader导入excel中文显示乱码(2013-12-04)
- ·Codeigniter 购物车类不能添加中文解决方法(2013-12-04)
- ·phpword中文字符乱码解决办法(2013-12-05)
- ·一个比较完善的购物车类(2013-12-08)
- ·php面象对象数据库操作类(2013-12-09)
- ·PHP顶层类(2013-12-10)
- ·PHP静态文件生成类(2013-12-10)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)