EmailController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. <?php
  2. /**
  3. * EmailController
  4. * Feel free to delete the methods and replace them with your own code.
  5. *
  6. * @author JieRen
  7. */
  8. class EmailController extends DooController {
  9. public $data;
  10. public $email_task;
  11. /**
  12. * 构造函数
  13. */
  14. function __construct() {
  15. session_start();
  16. $this->data ['rootUrl'] = Doo::conf ()->APP_URL;
  17. Load::logic ( 'Email' );
  18. $this->email_task = new EmailLogic ();
  19. }
  20. /**
  21. * 进入邮件管理
  22. */
  23. public function manage_Email() {
  24. if (empty($_SESSION['main'])) {
  25. return Doo::conf()->APP_URL . 'm';
  26. }
  27. // $url='http://sendcloud.sohu.com/webapi/list.create.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org&name=sso';
  28. // $result = file_get_contents($url);
  29. // $rs=json_decode($result,true);
  30. Doo::loadModel ( 'users' );
  31. $Users = new Users();
  32. $count=$Users->count(array('asArray'=>true));
  33. $url='http://sendcloud.sohu.com/webapi/list.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
  34. $result = file_get_contents($url);
  35. $rs=json_decode($result,true);
  36. // print_r($rs);
  37. // die();
  38. $this->data['count2']=0;
  39. if (!empty($rs['count']))
  40. $this->data['count2']=$rs['lists'][0]['members_count'];
  41. $this->data['count1']=$count;
  42. $d=date("Y-m-d");
  43. $url='http://sendcloud.sohu.com/webapi/stats.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&start_date='.$d.'&end_date='.$d;
  44. $result = file_get_contents($url);
  45. $rs=json_decode($result,true);
  46. $this->data['count']=50000-$rs['stats'][0]['request'];
  47. $this->data['selectemail'] = true;
  48. $this->render ( 'admin/mailListCreate', $this->data, TRUE );
  49. }
  50. function sendUP(){
  51. /*
  52. $url='http://sendcloud.sohu.com/webapi/list.delete.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
  53. $result = file_get_contents($url);
  54. die;
  55. */
  56. $url='http://sendcloud.sohu.com/webapi/list.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org';
  57. $result = file_get_contents($url);
  58. $rs=json_decode($result,true);
  59. if (empty($rs['count'])){
  60. $url='http://sendcloud.sohu.com/webapi/list.create.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&address=sso@maillist.sendcloud.org&name=sso';
  61. $result = file_get_contents($url);
  62. $rs=json_decode($result,true);
  63. }
  64. $Path = "./global/sso.json";
  65. //不存在文件创建
  66. if(!file_exists($Path)){
  67. file_put_contents($Path,0);
  68. }
  69. $id=file_get_contents($Path);
  70. Doo::loadModel ( 'users' );
  71. $Users = new Users();
  72. $start=$id;
  73. //$end=$id+1500;
  74. $end=500;
  75. $userList=$Users->find(array('limit'=>$start.','.$end,'asArray'=>true));
  76. /*
  77. foreach ($userList as $key=>$value){
  78. $userList[$key]['useremail']='cpthought@vip.qq.com';
  79. }
  80. //print_r($userList);
  81. //die;
  82. */
  83. $ul=array();$i=0;$pa=array();
  84. foreach ($userList as $key=>$value){
  85. array_push($pa, $value['useremail']);
  86. $falg=true;
  87. if ($i==99){
  88. array_push($ul, $pa);
  89. $i=0;$pa=array();
  90. $falg=false;
  91. }
  92. if ($falg)
  93. $i++;
  94. }
  95. $url = 'http://sendcloud.sohu.com/webapi/list_member.add.json';
  96. foreach ($ul as $value){
  97. $userT=implode(';', $value);
  98. $param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
  99. 'api_key' => 'cDO1GjtY1seH',
  100. 'mail_list_addr'=>'sso@maillist.sendcloud.org',
  101. 'upsert' =>'true',
  102. 'member_addr' => $userT
  103. );
  104. $post_data = http_build_query($param);
  105. $ch = curl_init();
  106. curl_setopt($ch, CURLOPT_POST, 1);
  107. curl_setopt($ch, CURLOPT_URL,$url);
  108. curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
  109. curl_setopt($ch, CURLOPT_NOBODY, false);
  110. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  111. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  112. $result =curl_exec($ch);
  113. curl_close($ch);
  114. $rs=json_decode($result,true);
  115. if ($rs['message']=='success'){
  116. $id=file_get_contents($Path);
  117. file_put_contents($Path,$id+100);
  118. }
  119. }
  120. return '/m/email';
  121. }
  122. public function createEmail(){
  123. if (empty($_SESSION['main'])) {
  124. return Doo::conf()->APP_URL . 'm';
  125. }
  126. $title = $this->get_args ( "title" );
  127. //$content = $_POST[ "content" ];
  128. $stype = $this->get_args ( "stype" );
  129. if(!empty($title)&&$stype==1){
  130. Doo::loadModel ( 'users' );
  131. $Users = new Users();
  132. Doo::loadModel('/m/emailList');
  133. $emailList = new emailList();
  134. // $list=$Users->find(array('select'=>'useremail','asArray'=>true));
  135. // $size=floor(count($list)/5);
  136. //
  137. // $list=array_chunk($list,$size);
  138. // $emailJson=array();
  139. // foreach ($list as $value){
  140. // $em=array();
  141. // foreach ($value as $v){
  142. // array_push($em, $v['useremail']);
  143. // }
  144. // array_push($emailJson, $em);
  145. // }
  146. $emailList->title=$title;
  147. //$emailList->content=$content;
  148. // $emailList->Email1=json_encode($emailJson[0]);
  149. // $emailList->Email2=json_encode($emailJson[1]);
  150. // $emailList->Email3=json_encode($emailJson[2]);
  151. // $emailList->Email4=json_encode($emailJson[3]);
  152. // $emailList->Email5=json_encode($emailJson[4]);
  153. $emailList->time=date("Y-m-d");
  154. $emailList->insert();
  155. return '/m/mailList';
  156. }elseif(!empty($title)&&$stype==2){
  157. /*
  158. $url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft1@zhzd.sendcloud.org';
  159. $result = @file_get_contents($url, false);
  160. $url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft2@zhzd.sendcloud.org';
  161. $result = @file_get_contents($url, false);
  162. $url='https://sendcloud.sohu.com/webapi/list_member.delete.xml?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&mail_list_addr=websoft3@zhzd.sendcloud.org';
  163. $result = @file_get_contents($url, false);
  164. //print_r($list);
  165. $sitePath=Doo::conf()->SITE_PATH.'protected/class/';
  166. $s1=file_get_contents($sitePath."20000.php", false);
  167. $s2=file_get_contents($sitePath."40000.php", false);
  168. $s3=file_get_contents($sitePath."60000.php", false);
  169. */
  170. Doo::loadModel('/m/emailList');
  171. $emailList = new emailList();
  172. $emailList->title=$title;
  173. //$emailList->content=$content;
  174. $emailList->stype=2;
  175. //$emailList->Email1=$s1;
  176. //$emailList->Email2=$s2;
  177. //$emailList->Email3=$s3;
  178. $emailList->time=date("Y-m-d");
  179. $emailList->insert();
  180. /*
  181. https://sendcloud.sohu.com/webapi/list_member.add.xml?api_user=username&api_key=password&mail_list_addr=developers@sendcloud.org
  182. &member_addr=john@sendcloud.org;to2@126.com&name=约翰;林肯&vars={"money": "1000"};{"money": "200"}&upsert=true
  183. */
  184. return '/m/mailList';
  185. }
  186. return '/m/email';
  187. }
  188. /*
  189. * 生成用户
  190. *
  191. $sitePath=Doo::conf()->SITE_PATH.'protected/controller/m/';
  192. $user=file_get_contents($sitePath."60000.txt", false);
  193. //readfile();
  194. $user=str_replace("\r\n",",",$user);
  195. $userList=explode(',',$user);
  196. $list=array();
  197. foreach ($userList as $value){
  198. $s=strpos($value,'<');
  199. $e=strpos($value,'>');
  200. $value=substr($value,$s);
  201. $value=substr($value,0,$e);
  202. $value=str_replace("<","",$value);
  203. $value=str_replace(">","",$value);
  204. array_push($list, $value);
  205. }
  206. $userList=json_encode($list);
  207. file_put_contents("60000.php", $userList);
  208. */
  209. function viewMail(){
  210. if (empty($_SESSION['main'])) {
  211. return Doo::conf()->APP_URL . 'm';
  212. }
  213. $eid = $this->params[ "eid" ];
  214. Doo::loadModel('/m/emailList');
  215. $emailList = new emailList();
  216. $eMailList=$emailList->getOne(array('where'=>'eid ='.$eid,'asArray'=>true));
  217. $this->data['eMailList']=$eMailList;
  218. $this->data['selectemail'] = true;
  219. $this->render ( 'admin/mailListView', $this->data, TRUE );
  220. }
  221. function mailList(){
  222. if (empty($_SESSION['main'])) {
  223. return Doo::conf()->APP_URL . 'm';
  224. }
  225. Doo::loadModel('/m/emailList');
  226. $emailList = new emailList();
  227. $list=$emailList->find(array('desc'=>'eid','asArray'=>true));
  228. $d=date("Y-m-d");
  229. $url='http://sendcloud.sohu.com/webapi/stats.get.json?api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&start_date='.$d.'&end_date='.$d;
  230. $result = @file_get_contents($url, false);
  231. $rs=json_decode($result,true);
  232. $this->data['count']=50000-$rs['stats'][0]['request'];
  233. $this->data['list']=$list;
  234. $this->data['selectemail'] = true;
  235. // $this->data['adminArray'] = $_SESSION['userArray'];
  236. $this->render ( 'admin/mailList', $this->data, TRUE );
  237. }
  238. function postEmail(){
  239. if (empty($_SESSION['main'])) {
  240. return Doo::conf()->APP_URL . 'm';
  241. }
  242. Doo::loadModel('/m/emailList');
  243. $eMList = new emailList();
  244. $eid=isset($this->params['eid'])?$this->params['eid']:0;
  245. $es=isset($this->params['es'])?$this->params['es']:0;
  246. if (!empty($eid)&&!empty($es)){
  247. $eMailList=$eMList->getOne(array('where'=>'eid ='.$eid.' and EmailName'.$es.'=""','asArray'=>true));
  248. //防止2次点击
  249. $sql = "update `zh_emailList` set EmailName".$es."='1' where eid = '" . $eid."'";
  250. Doo::db ()->query ( $sql );
  251. $toFormatMail=array();$sub=array();
  252. $toMail=json_decode($eMailList['Email'.$es],true);
  253. if ($eMailList['stype']==1){
  254. //'api_user=***&api_key=***&from=test@test.com&fromname=来自测试发送&subject=测试&template_invoke_name=ifaxin_bill&replyto=reply@test.com&label=16800&resp_email_id=true&use_maillist=true&to=users@maillist.sendcloud.org' http://sendcloud.sohu.com/webapi/mail.send_template.json
  255. $urlST='http://sendcloud.sohu.com/webapi/mail.send_template.json';
  256. $param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
  257. 'api_key' => 'cDO1GjtY1seH',
  258. 'from' =>'postmaster@zhzd.sendcloud.org',
  259. 'fromname' => '123',
  260. 'template_invoke_name'=>'sso_mail',
  261. //'subject' => $eMailList['title'],
  262. 'labelId'=>'5787',
  263. 'use_maillist'=>TRUE,
  264. 'to'=>'sso@maillist.sendcloud.org',
  265. );
  266. $post_data = http_build_query($param);
  267. $post_data='api_user=postmaster@zhzd.sendcloud.org&api_key=cDO1GjtY1seH&from=postmaster@zhzd.sendcloud.org&fromname=纵横软件&template_invoke_name=sso_mail&use_maillist=true&to=sso@maillist.sendcloud.org';
  268. $ch = curl_init();
  269. curl_setopt($ch, CURLOPT_POST, 1);
  270. curl_setopt($ch, CURLOPT_URL,$urlST);
  271. //curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
  272. //curl_setopt($ch, CURLOPT_NOBODY, false);
  273. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  274. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  275. $result =curl_exec($ch);
  276. curl_close($ch);
  277. return '/m/mailList';
  278. die;
  279. }
  280. if($eMailList['stype']==2){
  281. $sitePath=Doo::conf()->SITE_PATH.'protected/class/';
  282. if($es==1)
  283. $toMail=file_get_contents($sitePath."20000.php", false);
  284. if($es==2)
  285. $toMail=file_get_contents($sitePath."40000.php", false);
  286. if($es==3)
  287. $toMail=file_get_contents($sitePath."60000.php", false);
  288. $toMail=json_decode($toMail,true);
  289. }
  290. $chunkMail=array_chunk($toMail,80);
  291. foreach ($chunkMail as $key=>$value){
  292. $l=$con=array();
  293. $toFormatMail['to']=$value;
  294. //for ($cn=1;$cn<=count($value);$cn++){
  295. // array_push($l, $eMailList['title']);
  296. //array_push($con, $eMailList['content']);
  297. //}
  298. //$sub['%eTitle%']=$l;
  299. //$sub['%content%']=$con;
  300. //$toFormatMail['sub']=$sub;
  301. //print_r($toFormatMail);die;
  302. $url = 'http://sendcloud.sohu.com/webapi/mail.send_template.xml';
  303. $fromname='纵横软件';
  304. if($eMailList['stype']==2)
  305. $fromname='网络版';
  306. $param = array('api_user' => 'postmaster@zhzd.sendcloud.org',
  307. 'api_key' => 'cDO1GjtY1seH',
  308. 'template_invoke_name'=>'sso_mail',
  309. 'from' =>'postmaster@zhzd.sendcloud.org',// 'postmaster@zhzd.sendcloud.org',
  310. 'fromname' => $fromname,
  311. 'labelId'=>'5787',
  312. 'subject' => $eMailList['title'],
  313. 'substitution_vars' => json_encode($toFormatMail));
  314. $options = array('http' => array('method' => 'POST',"Content-type: application/x-www-form-urlencoded ",'content' => http_build_query($param)));
  315. $context = stream_context_create($options);
  316. if (!empty($toFormatMail['to'])){
  317. $result = file_get_contents($url, false, $context);
  318. }
  319. //if($result=='success'){
  320. // $eM=new eMailList();
  321. // $eM->status='2';
  322. // $eM->update(array('where'=>'elid=?','param'=>array($elid)));
  323. // }
  324. }
  325. return '/m/mailList';
  326. }
  327. }
  328. /**
  329. * 添加邮件任务
  330. */
  331. function manage_add_email_task() {
  332. $data ['email_title'] = $this->get_args ( "email_title" );
  333. $data ['email_content'] = $this->get_args ( "email_content" );
  334. if (empty ( $data ['email_title'] ) || empty ( $data ['email_content'] )) {
  335. echo "email_title is empty or email_content is empty";
  336. die ();
  337. }
  338. $id = $this->email_task->add_email_task ( $data );
  339. }
  340. /**
  341. * 发送邮件任务
  342. */
  343. function manage_send_email_task() {
  344. $tid = $this->check_params ( 'tid' );
  345. $tid = is_numeric ( $tid ) ? $tid : 0;
  346. if ($tid == 0) {
  347. echo "plase input tid";
  348. die ();
  349. }
  350. $e_task = $this->email_task->get_email_task_by_tid ( $tid );
  351. $i = 0;
  352. $faild_count = 0;
  353. $error_email = "";
  354. $faild_email = "";
  355. // foreach ( $e_task ['user_list'] as $key => $value ) {
  356. //
  357. // //邮件是否正确
  358. // if (filter_var ( $value ['useremail'], FILTER_VALIDATE_EMAIL )) {
  359. // //$value ['useremail'];
  360. // //邮件是否发送成功
  361. // $is_send = $this->email_task->send_email ( "cpthought@vip.qq.com",$e_task['email_title'],$e_task['email_content'] );
  362. //
  363. // if (! $is_send) {
  364. //
  365. // $faild_email .= $value ['useremail'] . ",";
  366. //
  367. // $faild_count ++;
  368. // }
  369. // $i ++;
  370. // } else {
  371. //
  372. // $error_email .= "邮箱不正确用户:" . $value ['username'] . "<br/>";
  373. // }
  374. // usleep(500000);
  375. // }
  376. // $this->data ['send_count'] = $e_task ['send_count'];
  377. //
  378. // $this->data ['is_send_count'] = $e_task ['is_send_count'] + $i;
  379. //
  380. // $percent = $this->data ['is_send_count'] / $e_task ['send_count'] * 100;
  381. //
  382. // $this->data ['percent'] = round ( $percent, 2 ) . "%";
  383. //
  384. // $this->data ['error_email'] = $error_email;
  385. //
  386. // $this->data ['faild_count'] = $faild_count;
  387. $this->data ['send_count'] = $e_task ['send_count'];
  388. $this->data ['is_send_count'] = 0;
  389. $this->data ['percent'] = "0%";
  390. $this->data ['error_email'] = "";
  391. $this->data ['faild_count'] = 0;
  392. $this->data ['tid'] = $tid;
  393. //更新邮件进度
  394. // $this->email_task->update_email_task_by_tid ( $tid, $this->data ['is_send_count'], $faild_email );
  395. //
  396. // if($this->data ['is_send_count']>=$this->data ['send_count']){
  397. //
  398. // $this->email_task->update_email_task_by_faild_email($tid);
  399. // }
  400. $this->render ( 'admin/issendMail', $this->data, TRUE );
  401. }
  402. /**
  403. * ajax发送邮件任务
  404. */
  405. function manage_ajax_send_email_task() {
  406. $tid = $this->check_params ( 'tid' );
  407. $tid = is_numeric ( $tid ) ? $tid : 0;
  408. if ($tid == 0) {
  409. echo "plase input tid";
  410. die ();
  411. }
  412. $e_task = $this->email_task->get_email_task_by_tid ( $tid );
  413. //群发邮件已完成
  414. if ($e_task ['status'] == 3 || $e_task ['status'] == 4) {
  415. $data_list ['is_over'] = 2;
  416. $json = json_encode ( $data_list );
  417. echo $json;
  418. return false;
  419. }
  420. $i = 0;
  421. $faild_count = 0;
  422. $error_email = "";
  423. $faild_email = "";
  424. if (! empty ( $e_task )) {
  425. require_once './protected/config/email_stmp.conf.php';
  426. $stmp_i = 0;
  427. foreach ( $e_task ['user_list'] as $key => $value ) {
  428. //邮件是否正确
  429. if (filter_var ( $value ['useremail'], FILTER_VALIDATE_EMAIL )) {
  430. //邮件是否发送成功 "cpthought@vip.qq.com"$value ['useremail'] 914630468@qq.com
  431. $is_send = $this->email_task->send_email ( $value ['useremail'], $e_task ['email_title'], $e_task ['email_content'], $stmp [$stmp_i] ['host'], $stmp [$stmp_i] ['port'], $stmp [$stmp_i] ['username'], $stmp [$stmp_i] ['password'], $stmp [$stmp_i] ['form'] );
  432. if (! $is_send) {
  433. $faild_email .= $value ['useremail'] . ",";
  434. $faild_count ++;
  435. }
  436. $stmp_i ++;
  437. if ($stmp_i == 30)
  438. $stmp_i = 0;
  439. $i ++;
  440. } else {
  441. $error_email .= "邮箱不正确用户:" . $value ['username'] . "<br/>";
  442. }
  443. usleep ( 50000 );
  444. }
  445. $data_list = array ();
  446. $data_list ['send_count'] = $e_task ['send_count'];
  447. $data_list ['is_send_count'] = $e_task ['is_send_count'] + $i;
  448. $percent = $data_list ['is_send_count'] / $e_task ['send_count'] * 100;
  449. $data_list ['percent'] = round ( $percent, 2 ) . "%";
  450. $data_list ['error_email'] = $error_email;
  451. $data_list ['faild_count'] = $faild_count;
  452. $data_list ['tid'] = $tid;
  453. $data_list ['is_over'] = 1;
  454. //更新邮件进度
  455. $this->email_task->update_email_task_by_tid ( $tid, $data_list ['is_send_count'], $faild_email );
  456. }
  457. if ($data_list ['is_send_count'] >= $data_list ['send_count']) {
  458. $data_list ['is_over'] = 2;
  459. $this->email_task->update_email_task_by_faild_email ( $tid );
  460. }
  461. $json = json_encode ( $data_list );
  462. echo $json;
  463. }
  464. /**
  465. * 发送邮件任务
  466. */
  467. function manage_faild_email_task() {
  468. $tid = $this->check_params ( 'tid' );
  469. $tid = is_numeric ( $tid ) ? $tid : 0;
  470. if ($tid == 0) {
  471. echo "plase input tid";
  472. die ();
  473. }
  474. $e_task = $this->email_task->get_faild_email_task_by_tid ( $tid );
  475. $faild_array = explode ( ",", $e_task ['faild_uid'] );
  476. $this->data ['send_count'] = count($faild_array);
  477. $this->data ['is_send_count'] = 0;
  478. $this->data ['tid'] = $tid;
  479. $this->render ( 'admin/isfaildMail', $this->data, TRUE );
  480. }
  481. /**
  482. * 发送失败文件
  483. */
  484. function manage_send_faild_email_task() {
  485. $tid = $this->check_params ( 'tid' );
  486. $tid = is_numeric ( $tid ) ? $tid : 0;
  487. if ($tid == 0) {
  488. echo "plase input tid";
  489. die ();
  490. }
  491. $e_task = $this->email_task->get_faild_email_task_by_tid ( $tid );
  492. $faild_email = "";
  493. $error_email="";
  494. if (! empty ( $e_task )) {
  495. //群发邮件已完成
  496. if ($e_task ['status'] != 3) {
  497. echo "send email is complate1";
  498. return false;
  499. }elseif(empty($e_task['faild_uid'])){
  500. $this->email_task->update_email_task_status_by_tid ( $tid, 4 );
  501. echo "send email is complate2";
  502. return false;
  503. }
  504. $faild_array = explode ( ",", $e_task ['faild_uid'] );
  505. require_once './protected/config/email_stmp.conf.php';
  506. $stmp_i = 0;
  507. $i=0;
  508. $k=$s="";
  509. foreach ($faild_array as $key=>$value){
  510. //邮件是否正确
  511. if (!empty($value)&&filter_var ( $value , FILTER_VALIDATE_EMAIL )) {
  512. //邮件是否发送成功 "cpthought@vip.qq.com" $value ['useremail'] 914630468@qq.com
  513. $is_send = $this->email_task->send_email ( $value , $e_task ['email_title'], $e_task ['email_content'], $stmp [$stmp_i] ['host'], $stmp [$stmp_i] ['port'], $stmp [$stmp_i] ['username'], $stmp [$stmp_i] ['password'], $stmp [$stmp_i] ['form'] );
  514. if (! $is_send) {
  515. $faild_email .= $value . ",";
  516. $k.= $value. ",";
  517. unset($faild_array[$i]);
  518. }else{
  519. $s.= $value. ",";
  520. unset($faild_array[$i]);
  521. }
  522. $stmp_i ++;
  523. if ($stmp_i == 30)
  524. $stmp_i = 0;
  525. } else {
  526. $error_email .= "邮箱不正确用户:" . $value . "<br/>";
  527. }
  528. usleep ( 50000 );
  529. if($i==28)
  530. break;
  531. $i++;
  532. }
  533. //
  534. $t=implode(",",$faild_array);
  535. $this->email_task->update_faild_email_task_by_tid ( $tid, $t );
  536. $this->email_task->de_faild_email_task_by_tid ( $tid, $e_task['de_email'].$faild_email );
  537. $data_list = array ();
  538. $data_list ['send_count'] = count($faild_array);
  539. $data_list ['is_send_count'] = $i+1;
  540. $data_list ['tid'] = $tid;
  541. $data_list['error_email']=$k;
  542. $data_list ['is_over'] = 1;
  543. if (count($faild_array) <= 0) {
  544. $data_list ['is_over'] = 2;
  545. }
  546. $json = json_encode ( $data_list );
  547. echo $json;
  548. }
  549. }
  550. /**
  551. * 删除邮件任务
  552. */
  553. function manage_delete_email_task() {
  554. $tid = $this->check_params ( 'tid' );
  555. $tid = is_numeric ( $tid ) ? $tid : 0;
  556. if ($tid == 0) {
  557. echo "plase input tid";
  558. die ();
  559. }
  560. $e_task = $this->email_task->delete_email_task_by_tid ( $tid );
  561. }
  562. /**
  563. * 获取get或者POST值
  564. * @param string $name 属性名称
  565. * @return fixed 值
  566. */
  567. function get_args($name) {
  568. if (isset ( $_GET [$name] )) {
  569. if (is_array ( $_GET [$name] ))
  570. return $_GET [$name];
  571. else
  572. return addslashes ( $_GET [$name] );
  573. } elseif (isset ( $_POST [$name] )) {
  574. if (is_array ( $_POST [$name] ))
  575. return $_POST [$name];
  576. else
  577. return addslashes ( $_POST [$name] );
  578. } else {
  579. return false;
  580. }
  581. }
  582. /**
  583. * 检测数据输入的非法字符和转义非法字符
  584. */
  585. function check_params($name = "") {
  586. if (isset ( $this->params [$name] )) {
  587. return mysql_escape_string ( $this->params [$name] );
  588. } else {
  589. return false;
  590. }
  591. }
  592. }
  593. ?>