您的位置:首页 > 其它

邮件服务器端发送

2012-07-04 16:44 706 查看
<?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';


转自天翼空间
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  邮件服务器