浏览 4151 次
锁定老帖子 主题:uchome中的发送邮件
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-07-14
//检查是否存在当前队列 $cid = 0; $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mailcron')." WHERE email='$email' LIMIT 1"); if($value = $_SGLOBAL['db']->fetch_array($query)) { $cid = $value['cid']; } else { $cid = inserttable('mailcron', array('email'=>$email), 1); } if($cid) { //插入邮件内容队列 $setarr = array( 'cid' => $cid, 'subject' => "product invite", 'message' => "product invite", 'dateline' => $_SGLOBAL['timestamp'] ); inserttable('mailqueue', $setarr); } 2:使用source/do_sendmail.php发送邮件,ssetcookie('sendmail', '1', 300);//用户每5分钟调用本程序 ssetcookie('sendmail', '1', 300);//用户每5分钟调用本程序 $lockfile = S_ROOT.'./data/sendmail.lock'; @$filemtime = filemtime($lockfile); if($_SGLOBAL['timestamp'] - $filemtime < 5) exit(); touch($lockfile); //防止超时 set_time_limit(0); //获取发送队列 $list = $sublist = $cids = $touids = array(); $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mailcron')." WHERE sendtime<='$_SGLOBAL[timestamp]' ORDER BY sendtime LIMIT 0,$pernum"); while ($value = $_SGLOBAL['db']->fetch_array($query)) { if($value['touid']) $touids[$value['touid']] = $value['touid']; $cids[] = $value['cid']; $list[$value['cid']] = $value; } if(empty($cids)) exit(); //邮件内容 $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('mailqueue')." WHERE cid IN (".simplode($cids).")"); while ($value = $_SGLOBAL['db']->fetch_array($query)) { $sublist[$value['cid']][] = $value; } //开始发送 include_once(S_ROOT.'./source/function_sendmail.php'); foreach ($list as $cid => $value) { $mlist = $sublist[$cid]; if($value['email'] && $mlist) { $subject = getstr($mlist[0]['subject'], 80, 0, 0, 0, 0, -1); $message = ''; foreach ($mlist as $subvalue) { if($subvalue['message']) { $message .= "<br><strong>$subvalue[subject]</strong><br>$subvalue[message]<br>"; } else { $message .= $subvalue['subject'].'<br>'; } } if(!sendmail($value['email'], $subject, $message)) { runlog('sendmail', "$value[email] sendmail failed."); } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |