<?php
defined('PP_PATH') or exit('Access Denied');
class other extends model {
	
	//邮件发送
	public function sendmail($username, $email, $subject, $message) {
		$mailconf = $this->kv->get('mail_cfg');
	
		if( empty($mailconf) ) return '未获取到邮件配置信息';
		
		if($mailconf['sendtype'] == 0) {			
			$subject = iconv('UTF-8', 'GBK', $subject);
			$message = iconv('UTF-8', 'GBK', $message);
			mail($email, $subject, $message, NULL, NULL);			
		} elseif($mailconf['sendtype'] == 1) {			
			// $key = array_rand($mailconf['smtplist']);			
			// $smtp = $mailconf['smtplist'][$key];
			$smtp = $mailconf['smtplist'];
				
			$message = str_replace("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />", "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\" />", $message);
			$subject = iconv('UTF-8', 'GBK', $subject);
			$message = iconv('UTF-8', 'GBK', $message);
			$username = iconv('UTF-8', 'GBK', $username);
			return pp_mail::send($smtp, $username, $email, $subject, $message);				
		}
	}
}
