| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 | 
							- <?php
 
- require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');
 
- require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');
 
- class ajaxAction extends Action{
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 	}
 
- 	
 
- 	function sendemail(){
 
- 		$secret = "cd8412beb15b4ad34d8408d46e3c30a7";
 
- 		$getSecret = $_REQUEST['secret'];
 
- 		$store_name = $_REQUEST['store_name'];
 
- 		$customer_list = $_REQUEST['list'];
 
- 		$type = $_REQUEST['type'];//发送主题,1是询问收货地址;2确认收货
 
- 		//echo $store_name;exit;
 
- 		//测试数据
 
- //		$getSecret = $secret;
 
- //		$store_name = "alipearlhair";
 
- //		$type = 2;
 
- //		$customer_list = array(
 
- //			"1" => array("email"=>"lxk8875@yahoo.com","logistics_number"=>"888888","uname"=>"hcm"),
 
- //			"2" => array("email"=>"hcmdd888@hotmail.com","logistics_number"=>"888888","uname"=>"hcm"),
 
- //		);
 
- 		//end
 
- 		$count = count($customer_list);//发送数量
 
- 		if($secret!=$getSecret){
 
- 			//密钥有误
 
- 			echo 1;exit;
 
- 		}
 
- 		if(empty($store_name)){
 
- 			//没传店铺名;
 
- 			echo 2;exit;
 
- 		}
 
- 		if($type!=1 && $type!=2){
 
- 			//发送主题,1是询问收货地址;2确认收货
 
- 			echo 3;exit;
 
- 		}
 
- 		global $EMAIL_MSG_LIST;
 
- 		global $EMAIL_SUBJECT_LIST;
 
- 		$subject = $EMAIL_SUBJECT_LIST[$store_name][$type];
 
- 		$admin = new AdvertAdminAction();
 
- 		//alipearlhair
 
- 		$info = $admin->selectUserByName($store_name);
 
- 		$api_user = $info['api_user'];
 
- 		$api_key  = $info['api_key'];
 
- 		$from     = $info['email_from'];
 
- 		$replyto  = $info['email'];//发件人邮箱地址
 
- 		$content = $EMAIL_MSG_LIST[$store_name][$type];
 
- 		$post_url = 'http://api.sendcloud.net/apiv2/mail/send';
 
- 		//假设一次只能给100个人发,看需要发几次
 
- 		$c = 100;
 
- 		$p = ceil($count/100);//需要发总次数
 
- 		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'][] =  $list['email'];
 
- 					$user_name = $list['uname'];
 
- 					$x_smtpapi['sub']['%name%'][] =  $user_name;
 
- 					if($type==1){
 
- 						$x_smtpapi['sub']['%address%'][] =  $list['address'];
 
- 					}
 
- 					if($type==2){
 
- 						$x_smtpapi['sub']['%logistics_number%'][] =  $list['logistics_number'];
 
- 					}
 
- 				}
 
- 			}
 
- 			$x_smtpapi = json_encode($x_smtpapi);
 
- 			$params = array(
 
- 					'apiUser' => $api_user,
 
- 					'apiKey'  => $api_key,
 
- 					'xsmtpapi' => $x_smtpapi,
 
- 					'from'     => $from,
 
- 					'subject' => $subject,
 
- 					'html'    =>  $content,
 
- 					'replyto' => $replyto
 
- 			);
 
- 			$result = make_curl($post_url,$params);
 
- 			//插入 普通邮件发送日志表
 
- 			$params['uid'] = $info['id'];
 
- 			$params['message'] = $result['message'];
 
- 			$params['time'] = time();
 
- 			$params['to']   = $params['xsmtpapi'];
 
- 			$insert_log = $admin->inserEmail1Log($params);
 
- 		}
 
- 		$msg = $result['message'];
 
- 		//成功
 
- 		echo 5;exit;
 
- 	}
 
- 	
 
- }
 
 
  |