郵件服務器端發送

 


<?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';

 

轉自天翼空間
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章