1. 程式人生 > php教程 > 郵件伺服器端傳送_PHP教程

郵件伺服器端傳送_PHP教程

<?php//set_time_limit(0);//echo 'hudie';//die();//error_reporting(E_ALL); //郵件群發 $send_class_path = 'SendmailClass.php'; if(file_exists($send_class_path)){ include($send_class_path); $EmailClass = new Sendmail(); }else{ exit ('The email class is not exist'); } $mid = isset($argv['1']) ? intval($argv['1']) : ''; $amount = isset($argv['2']) ? intval($argv['2']) : 100000 ; define('APP_PATH', '../app/cache/'); $midpath = APP_PATH.'midarr.php'; if(file_exists($midpath)){ $midarr = include_once($midpath); }else{ $midarr = array(); } if($mid){ if(! in_array($mid,$midarr)){ exit ('Message not exist'); } $nmid = array($mid=>$mid); }else{ $nmid = $midarr; } $t = $m = 0; foreach ($nmid as $k => $mid) { $epath = APP_PATH.'emaillist_'.$mid.'.php'; $hadsend = APP_PATH.'krecord_'.$mid.'.php'; $emailmodel = APP_PATH.'emodel_'.$mid.'.php'; $emodel = include($emailmodel); $krecord = file_get_contents($hadsend); $userinfo = array(); if($krecord < $emodel['count']) { $beginnum = $krecord + 1; //獲取需要傳送的使用者列表 if(file_exists($epath)){ $fop = @fopen($epath,"r"); if(!$fop){ exit('Read epath error!'); } while(!feof($fop)) { $m++; $one = fgets($fop); if($m < $beginnum) { continue; } list($uid,$username,$email) = @explode("/t",$one); //過濾錯誤的型別 if(!empty($uid) &;&; !empty($username) &;&; !empty($email)) { $userinfo[$m] = array('email'=>$email,'username'=>$username); } } fclose($fop); } else { exit('No emaillist_file'); } //開始傳送郵件 foreach ($userinfo as $u => $v) { /***************記錄傳送點*******************/ $fp = @fopen($hadsend, 'w'); if(!$fp) { exit('Write error!'); } if(flock($fp, LOCK_EX)) { fwrite($fp, $u); flock($fp, LOCK_UN); $res = true; } fclose($fp); /*********************開始傳送**************************/ if($res){ $subject = $emodel['theme']; $content = $emodel['content']; $toemail = $v['email']; $tousername = $v['username']; $EmailClass->sendPreHandle($toemail, $subject, $content, $tousername); $t++; //echo 'Sent '.$u.' --amount '.$t."/n"; if(!($t%3)){ sleep(3); } } if($t == $amount){ exit ("Finish sending/n"); //break 2; } } } } if($t) { echo 'Finish sending'; } else echo 'No email need to send';