[日常] 读取队列并循环发信的脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | <?php /** * 发送群发邮件脚本 * 查询队列内列表,循环调用smtp发送邮件 */ $emlDir = "/mnt/entmail/mass_mail/" ; //读取redis数据 $socket = fsockopen ( "tcp://xxx" ,6379, $errno , $errstr ); $smtp = new Smtp(); $second =0; $delSecond =0; while (true){ fwrite( $socket , "rpop send_mass_mail \r\n" ); $queue = '' ; $i =0; while (! feof ( $socket )) { $i ++; $ln =trim( fgets ( $socket )); $queue =( $ln == '$-1' ) ? '' : $ln ; if ( $i >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 ; } } |
十年开发经验程序员,离职全心创业中,历时三年开发出的产品《唯一客服系统》
一款基于Golang+Vue开发的在线客服系统,软件著作权编号:2021SR1462600。一套可私有化部署的网站在线客服系统,编译后的二进制文件可直接使用无需搭开发环境,下载zip解压即可,仅依赖MySQL数据库,是一个开箱即用的全渠道在线客服系统,致力于帮助广大开发者/公司快速部署整合私有化客服功能。
开源地址:唯一客服(开源学习版)
官网地址:唯一客服官网
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2017-03-22 [Linux] PHP程序员玩转Linux系列-Linux和Windows安装nginx
2016-03-22 [angularjs] angularjs系列笔记(四)过滤器
2016-03-22 [android] 显示意图激活另外一个activity
2016-03-22 [android] smartimageview&常见的开源代码