| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 | <?php /** * 邮件发送,普通发送,使用xsmtpapi发送 */require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');header('content-Type: text/html; charset=utf-8');class Send_email2_adminAction extends Action{		public function __construct(){		parent::__construct();		if(empty($_SESSION['mds_user'])){			header("Location:/?a=index&m=admin_login");			exit();		}	}	public function index(){		$api_user = $_SESSION['API_USER'];		$api_key  = $_SESSION['API_KEY'];		$from     = $_SESSION['FROM'];		$info     = $_REQUEST['info'];		$uid      = $_SESSION['user_infos']['id'];		$post_url = 'http://api.sendcloud.net/apiv2/mail/send';				$fromName = '';		switch($uid){			case 6:				$fromName = 'SuperNova Hair';				break;			case 1:				$fromName = 'Alipearl Hair';				break;			case 3:				$fromName = 'Westkiss Hair';				break;			case 4:				$fromName = 'Wiggins Hair';				break;			case 5:				$fromName = 'Asteria Hair';				break;			case 7:				$fromName = 'Yolissa Hair';				break;			case 8:				$fromName = 'Mellow Hair';				break;		}		$admin = new AdvertAdminAction();		//查询所有的邮件模板		$where = "where uid='{$_SESSION['user_infos']['id']}' and type=1 and status=1";		$template_list  = $admin->select_msg_list($where);		//查询所有的用户分组		$where2 = "where uid='$uid' ";		$group_list = $admin->select_user_group($where2);		/*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){			$where3.=" and group_name='{$_POST['group_name']}'";		}		$customer_list = $admin->selesctCustomer($where3);*/				/*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){			$where3.=" and group_name='{$_POST['group_name']}'";			$customer_list = $admin->selesctCustomer($where3);		}elseif(!empty($_POST['group_name']) && $_POST['group_name']=='all'){		    $customer_list = $admin->selesctCustomer($where2);		}		$count = count($customer_list);		//假设一次只能给100个人发,看需要发几次		$c = 100;		$p = ceil($count/100);//需要发总次数*/				$where3 = "where uid='$uid'";		if(!empty($_POST['group_name'])){		    if($_POST['group_name'] != 'all'){		        $where3.=" and group_name='{$_POST['group_name']}'";		        $customer_list = $admin->selesctCustomer($where3);		    }elseif($_POST['group_name'] == 'all'){		        $customer_list = $admin->selesctCustomer($where2);		    }		    $count = count($customer_list);		    		    //假设一次只能给100个人发,看需要发几次		    $c = 100;		    $p = ceil($count/100);		}		if($_POST['template_id']){			$id				= $_POST['template_id'];			$one_info 		= $admin->select_one_template($id);			$subject = str_replace("'", '', $one_info['msg_title']);			$content = str_replace("'", '', $one_info['msg_content']);			$replyto = $_SESSION['user_infos']['email'];//发件人邮箱地址			for($i=1;$i<=$p;$i++){				$min = $c*($i-1);				/*$max = $c*$i;*/				$x_smtpapi = array();				/*foreach($customer_list as $key=>$list){					if($key>=$min && $key<$max){						$x_smtpapi['to'][] =  trim($list['email']);						$user_name = $list['uname'];						$x_smtpapi['sub']['%name%'][] =  $user_name;					}				}*/				//start				$customer_list_now = array_slice($customer_list, $min, $c);				foreach($customer_list_now as $key=>$list){			        $x_smtpapi['to'][] =  trim($list['email']);			        $user_name = str_replace("'", '', $list['uname']);			        $x_smtpapi['sub']['%name%'][] =  $user_name;				}				//end								/*$x_smtpapi = json_encode($x_smtpapi);				$x_smtpapi = str_replace("\ufeff","",$x_smtpapi);				$x_smtpapi = str_replace("\u00a0","",$x_smtpapi);*/				$params = array(						'apiUser' => $api_user,						'apiKey'  => $api_key,						'xsmtpapi' => $x_smtpapi,						'from'     => $from,						'subject' => $subject,						'html'    =>  $content,						'fromName' => $fromName,						'replyto' => $replyto,						'uid' => $uid				);				/*$result = make_curl($post_url,$params);				//插入 普通邮件发送日志表				$params['uid'] = $uid;				$params['message'] = $result['message'];				$params['time'] = time();				$params['to']   = $params['xsmtpapi'];				$insert_log = $admin->inserEmail1Log($params);*/								//start				$params_arr[] = $params;				//end			}			$datetime = empty($_POST['demo_datetime']) ? date("Y-m-d H:i:s", time()) : $_POST['demo_datetime'];			//start			$result = $admin->add_email_data_queue($params_arr, $datetime);						if($result){			    $info = '邮件已进入待发送队列';							}else{			    $info = '邮件发送失败';			}			//end						header("Location:/?a=send_email2_admin&m=index&info=$info");			exit();		}		$email = $admin->selectEmailTmpData();		$this->assign('email_counts', $email[0]['ct']);				$this->assign('group_list',$group_list);		$this->assign('info',$info);		$this->assign('template_list',$template_list);		$this->display("index.html");	}	// class   end}?>
 |