php开发群发邮件功能

浏览:2361 最后更新:2017-04-21 17:58 分类:其他 关键字: 群发邮件
最近整了一个群发邮件的功能,虽然有点不科学,但是只要不乱来还是可能借鉴的

首先我设定了4张表,一张发送者、一张接收者、一张内容、一张记录
外加config配置

其实我做的很简单,就是利用了phpemalir插件,然后循环了数据而已。 /**
    * @name: 发送邮件
    * @date: 2017-03-29
    * @author: 小鼠鱼
    * @email: cxword@163.com 
    * @return:
    */
    public function receiveSend(){
        $cxmodel = C('CX_CXWORD_MODEL');
        $cxcont = C('EAMIL_CONTENT');
        $cxcont2= C('EAMIL_CONTENTS');
        $uid = session("CX_CXWORD_USERID");
        if (IS_AJAX) {
            $gongz = I('post.gongz');
            $cxone = I('post.cxone');
            $cxtwo = I('post.cxtwo');
            $cxthere = I('post.cxthere');
            //定义变量 循环接收方信息
            if ($cxone == 0) {
                $ucc = 0;
                $err = 0;
            } else {
                $ucc = session('ucc'); 
                $err = session('err');
            }
            //读取发送方信息
            $cxemail = D($cxmodel['MGROUP'])->cx_sendoutAll($uid);
            //读取接收方信息
            $cxemail2 = D($cxmodel['MGROUP'])->cx_receiveAll($uid,$gongz);
            //读取文本方信息
            $cxemail3 = D($cxmodel['MGROUP'])->cx_textId($uid,$cxthere);
            
            if ($cxone<count($cxemail2)) {
                
                if ($cxtwo<count($cxemail)) {
                    
                } else {
                    $cxtwo = 0;
                }
                
                //发送方参数
                    $data = array(
                        'MAIL_HOST'      => $cxemail[$cxtwo]['email_smtp'],
                        'MAIL_SMTPAUTH'  => TRUE,
                        'MAIL_USERNAME'  => $cxemail[$cxtwo]['email_title'],
                        'MAIL_PASSWORD'  => $cxemail[$cxtwo]['email_pass'],
                        'MAIL_FROM'      => $cxemail[$cxtwo]['email_address'],
                        'MAIL_FROMNAME'  => $cxemail[$cxtwo]['email_name'],
                        'MAIL_CHARSET'   => $cxcont2['MAIL_CHARSET'],
                        'MAIL_ISHTML'    => TRUE,
                        'MAIL_TO'        => $cxemail2[$cxone]['group_url'],
                        'TITLE'          => $cxemail3['email_title'],
                        'CONTENT'        => $cxemail3['email_content']
                        );
                   
                    $cxinfo = cx_SendEmail($data); //sleep(3);
                    $cxone++; $cxtwo++; //$cxthere++;
                    $cxdata =array(
                        'cxone'  => $cxone,
                        'cxtwo'  => $cxtwo,
                        'cxthere' => $cxthere,
                        'gongz' => $gongz
                        );
                    if ($cxinfo) {
                        // $groupdata = array(
                        //     'group_click' => $cxemail2[$cxone-1]['group_click']+1,
                        //     'group_endtime' => time()
                        //     );
                        $ucc++;
                        session('ucc',$ucc);
                        $back = array('cxss'=>true,'cxcan'=>'已成功!','cxfeng'=>$cxone,'retu'=>$data,'cxword'=>$cxdata);
                    } else {
                        $err++;
                        session('err',$err);
                        $back = array('cxss'=>true,'cxcan'=>'已失败!','cxfeng'=>$cxone,'retu'=>$data,'cxword'=>$cxdata);
                    }
            } else {
                
                $back = array('cxss'=>false,'cxcan'=>'<br>邮件发送成功共'.$ucc.'封!<br/>邮件发送失败共'.$err.'封!','cxfeng'=>$cxone,'retu'=>$data,'cxword'=>$cxdata);
                
            }
            
        }
        $this->ajaxReturn($back);
        
       
    }
做了一个导入数据表就这样。有兴趣可以玩玩,全特么垃圾邮件去了,想哭。。。
上传一个phpmailer.php 发送邮件的插件试试
评论( 相关
后面还有条评论,点击查看>>