- class emailui
- {
- 정적 함수 runlog($mode = 'SMTP',$b = '',$c = '',$d='') {
-
- }
- 정적 함수 sendmail($toemail, $subject, $message, $from='',$cfg = array(), $sitename='') {
- 전역 $db_wwwname ,$mail_port,$mail_id,$mail_server,$mail_pw,$mail_type,$db_charset,$version,$smtpfrom;
-
- $sitename = $sitename ? $sitename : $db_wwwname;
- $adminemail = $ mail_id ? $mail_id : 'admin@54ui.com';
-
- if($cfg && is_array($cfg)) {
- $adminemail = $cfg['from'];
- $mail_type = $cfg['mail_type']; //메일 전송 모드
- $mail = $cfg;
- } else {
- $adminemail = $mail_type; //Mail 송신 모드
- #포트, 메일 헤더 구분자, 수신자 주소에 포함된 사용자 이름
- $mail= Array (
- 'mailsend' => 2,
- 'maildelimiter' => 1,
- 'mailusername' => 1,
- '서버' => $mail_server, #Server
- 'port' => $mail_port, #Port
- $mail_id, #저자
- 'from' => $mail_id, #Sender
- 'auth_username' => $mail_id, #Account
- 'auth_password' => $mail_pw #Password
- > }
- //메일 전송 모드
- if(!$mail_type) {
- $headers = 'MIME-Version: 1.0' . "rn";
- $headers .= ' 콘텐츠 유형: text/html; charset='.$db_charset.'' . "rn";
- $headers .= 'From: '.$from.'>'
- mail($toemail, $subject, $message, $headers);
- return true;
- }
- //이메일 헤더 구분 기호
- $maildelimiter = $mail ['maildelimiter'] = = 1 ? "rn" : ($mail['maildelimiter'] == 2 ? "r" : "n");
- //수신자 주소에는 사용자 이름이 포함됩니다
- $mailusername = isset($mail ['mailusername']) ? $mail['mailusername'] : 1;
- //포트
- $mail['port'] = $mail['port'] ? 25;
- $mail['mailsend'] = $mail['mailsend'] ? $mail['mailsend'] : 1;
- //보내는 사람
- $email_from = $from == '' ? '=?'.$db_charset.'?B?'.base64_encode($sitename)."?= <".$adminemail.">" : (preg_match('/^( . ?) <(. ? )>$/',$from, $mats) ? '=?'.$db_charset.'?B?'.base64_encode($mats[1])."?= < $mats[2]>" : $from);
- //수신자
- $email_to = preg_match('/^(. ?) <(. ?)>$/',$toemail, $mats) ? ($mailusername ? ' =?'.$db_charset.'?B?'.base64_encode($mats[1])."?= <$mats[2]>" : $mats[2] ) : $toemail;;
- //이메일 제목
- $email_subject = '=?'.$db_charset.'?B?'.base64_encode(preg_replace("/[r|n]/", '', $subject.'--'.$ db_wwwname)).'?=';
- //메일 내용
- $message = $message."게시 위치: ".gmdate( "Y-m-d h:i:s", mktime() 8*3600)." , Powered By uicms ".$version." (service.54ui.com)";
- $email_message = Chunk_split( base64_encode(str_replace("n", " rn", str_replace("r", "n", str_replace("rn", "n", str_replace("nr", "r", $message)))))) ;
-
- $headers = "보낸 사람: $email_from{$maildelimiter}X 우선 순위: 3{$maildelimiter}X-Mailer: abaoei cms {$maildelimiter}MIME 버전: 1.0{$maildelimiter}콘텐츠 유형: text/html; charset=". $db_charset."{$maildelimiter}콘텐츠 전송 인코딩: base64{$maildelimiter}";
-
- if(!$fp = fsockopen($mail['server' ], $mail['port'] , $errno, $errstr, 30)) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) CONNECT - SMTP 서버에 연결할 수 없습니다.", 0) ;
- return false;
- }
- stream_set_blocking($fp, true);
-
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0 , 3) != '220') {
- self::runlog('SMTP', "$mail[server]:$mail[port] CONNECT - $lastmessage", 0 );
- return false;
- }
-
- fputs($fp, ($mail['auth'] ? 'EHLO' : 'HELO')." uchomern");
- $ lastmessage = fgets($fp, 512) ;
- if(substr($lastmessage, 0, 3) != 220 && substr($lastmessage, 0, 3) != 250) {
- self::runlog( 'SMTP', "($mail[ server]:$mail[port]) HELO/EHLO - $lastmessage", 0);
- return false;
- }
-
- while(1) {
- if(substr($lastmessage , 3, 1) != '-' || 비어 있음($lastmessage)) {
- break;
- }
- $lastmessage = fgets($fp, 512) ;
- }
-
- if($mail['auth']) {
- fputs($fp, "AUTH LOGINrn");
- $lastmessage = fgets($fp, 512);
- if( substr($lastmessage, 0, 3) != 334) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) 인증 로그인 - $lastmessage", 0);
- false 반환;
- }
-
- fputs($fp, base64_encode($mail['auth_username'])."rn");
- $lastmessage = fgets($fp, 512) ;
- if(substr($lastmessage, 0, 3) != 334) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) USERNAME - $lastmessage ", 0);
- 반환 false;
- }
-
- fputs($fp, base64_encode($mail['auth_password'])."rn");
- $lastmessage = fgets( $fp, 512);
- if(substr($lastmessage, 0, 3) != 235) {
- self::runlog('SMTP', "($mail[server]:$mail[port] ) 비밀번호 - $lastmessage", 0);
- false 반환;
- }
-
- $email_from = $mail['from'];
- }
-
- fputs($ fp, "MAIL FROM: <".preg_replace("/.*<(. ?)>.*/", "\1", $email_from).">rn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0, 3) != 250) {
- fputs($fp, "MAIL FROM: <".preg_replace("/.* <(. ?)>.*/", "\1", $email_from).">rn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0 , 3) != 250) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) MAIL FROM - $lastmessage", 0);
- return false;
- }
- }
-
- fputs($fp, "RCPT TO: <".preg_replace("/.*<(. ?)>.*/", "\1" , $toemail).">rn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0, 3) != 250) {
- fputs( $fp, "RCPT 대상: <".preg_replace("/.*<(. ?)>.*/", "\1", $toemail).">rn");
- $ lastmessage = fgets($fp, 512);
- self::runlog('SMTP', "($mail[server]:$mail[port]) RCPT TO - $lastmessage", 0);
- return false;
- }
-
- fputs($fp, "DATArn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0, 3) != 354) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) DATA - $lastmessage", 0);
- return false;
- }
-
- $headers .= '메시지 ID: <'.gmdate('YmdHs').'.'.substr(md5($email_message.microtime()), 0, 6).rand(100000 , 999999).'@'.$_SERVER['HTTP_HOST'].">{$maildelimiter}";
-
- fputs($fp, "날짜: ".gmdate('r')."rn ");
- fputs($fp, "받는 사람: ".$email_to."rn");
- fputs($fp, "제목: ".$email_subject."rn");
- fputs( $fp, $headers."rn");
- fputs($fp, "rnrn");
- fputs($fp, "$email_messagern.rn");
- $lastmessage = fgets($fp , 512);
- if(substr($lastmessage, 0, 3) != 250) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) END - $lastmessage", 0);
- }
- fputs($fp, "QUITrn");
- return true;
- }
- }
- //emailui::sendmail(' admin33@163.com', '你好哦', '비常感谢');
复主代码
|