博客
关于我
[日常] 读取队列并循环发信的脚本
阅读量:651 次
发布时间:2019-03-15

本文共 3886 字,大约阅读时间需要 12 分钟。

1 || $ln=='$-1'){ break; } } if(empty($queue)){ $delSecond++; var_dump($second); sleep(1); //发送完之后删掉邮件文件,延迟几十秒再删 if(is_dir($emlDir) && $delSecond>=50){ rrmdir($emlDir); var_dump($emlDir); } }else{ var_dump($queue); send($queue); $delSecond=0; } $second++;}fclose($socket);die;/** * 取出队列内容后发送邮件 * @param type $row */function send($row){ if(empty($row)) return; global $smtp; list($from,$to,$eml)= explode('|', $row); if(!is_file($eml)){ return; } $to=trim($to); if(empty($to)){ return; } $data=''; //$eml="/tmp/2.eml";var_dump($eml); $file=fopen($eml,"r"); while(!feof($file)){ $line=fgets($file); $tmp=preg_replace("/^To(.*)/i","TO: {$to}", $line); $data.=$tmp; } //var_dump($data);die; //$data=file_get_contents("/tmp/2.eml"); //$tmp=preg_replace("/\nTo[\w\W]*Subject/i","\nTO: {$to}\r\nSubject", $data);var_dump($tmp);die; $res=$smtp->connect("intraxxx",2025); $res.=$smtp->helo($from); $res.=$smtp->auth(); $res.=$smtp->user(); $res.=$smtp->pass("xxx"); $res.=$smtp->mailFrom($from); $res.=$smtp->rcpt($to); $res.=$smtp->data(); $res.=$smtp->send($data); //var_dump(error_get_last()); //echo $res;}/** * 删除邮件文件目录 * @param type $src */function rrmdir($src) { $dir = opendir($src); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { $full = $src . '/' . $file; if ( is_dir($full) ) { rrmdir($full); } else { unlink($full); } } } closedir($dir); rmdir($src);}class Smtp{ private $socket; private $email; public function __construct(){ ini_set('memory_limit', '1020M'); ini_set("auto_detect_line_endings", true); } public function connect($smtpServer,$smtpPort){ $res=@fsockopen("tcp://".$smtpServer,$smtpPort,$errno, $errstr,30); if(!$res){ throw new Exception($errstr, $errno); } $this->socket=$res; return $this->readLine(); } public function helo($email){ $user="HELO {$email}\r\n"; fwrite($this->socket,$user); $this->email=$email; return $this->readLine(); } public function auth(){ $pass="AUTH LOGIN\r\n"; fwrite($this->socket,$pass); return $this->readLine(); } public function user(){ $pass=base64_encode($this->email)."\r\n"; fwrite($this->socket,$pass); return $this->readLine(); } public function pass($pwd){ $pass=base64_encode($pwd)."\r\n"; fwrite($this->socket,$pass); return $this->readLine(); } public function mailFrom($from){ $data="MAIL FROM:<{$from}>\r\n"; fwrite($this->socket,$data); return $this->readLine(); } public function rcpt($rcpt){ $data="RCPT TO:<{$rcpt}>\r\n"; fwrite($this->socket,$data); return $this->readLine(); } public function data(){ $email="data\r\n"; fwrite($this->socket,$email); return $this->readLine(); } public function send($data){ $email="{$data}\r\n"; $email.=".\r\n"; fwrite($this->socket,$email); return $this->readLine(); } public function read() { $buf=""; while ($ln = $this->readLine()) { if (trim($ln) == '.') { break; } $buf .= $ln; } return $buf; } public function readLine(){ $result=""; while(true){ $buffer=@fgets($this->socket,128); $n = strlen($buffer); $result.=$buffer; if (!$n) { break; } if ($buffer[$n - 1] == "\n") { break; } } return $result; }}

  

转载地址:http://xpnmz.baihongyu.com/

你可能感兴趣的文章
Node-RED中使用html节点爬取HTML网页资料之爬取Node-RED的最新版本
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用node-red-contrib-image-output节点实现图片预览
查看>>
Node-RED中使用node-red-node-ui-iframe节点实现内嵌iframe访问其他网站的效果
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中使用range范围节点实现从一个范围对应至另一个范围
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Vue3+elementplus实现图片上传下载(最强实践)
查看>>
Node-RED中将CSV数据写入txt文件并从文件中读取解析数据
查看>>
Node-RED中建立TCP服务端和客户端
查看>>
Node-RED中建立Websocket客户端连接
查看>>
Node-RED中建立静态网页和动态网页内容
查看>>
Vue3+Element-ul学生管理系统(第二十二课)
查看>>
Node-RED中怎样让网站返回JSON数据
查看>>
Node-RED中根据HTML文件建立Web网站
查看>>
Node-RED中解析高德地图天气api的json数据显示天气仪表盘
查看>>
Node-RED中连接Mysql数据库并实现增删改查的操作
查看>>