Vhelin 发表于 2012-10-25 23:39:32

邮件服务器端发送

<?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 => $md) {            $epath      = APP_PATH.'emaillist_'.$md.'.php';            $hadsend    = APP_PATH.'krecord_'.$md.'.php';            $emailmodel = APP_PATH.'emodel_'.$md.'.php';            $emodel   = include($emailmodel);            $krecord    = intval(file_get_contents($hadsend));            $userinfo   = array();            if($krecord < $emodel['count']) {                $beginnum = $krecord + 1;                //获取需要发送的用户列表                if(file_exists($epath)){                  $fop = @fopen($epath,"rb");                  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, 'r+b');                  if(!$fp) {                        exit('Write error!');                  }            $u = intval($u);                  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';
页: [1]
查看完整版本: 邮件服务器端发送