- class emailui
- {
- static function runlog($mode = 'SMTP',$b = '',$c = '',$d='') {
-
- }
- static function sendmail($toemail, $subject, $message, $from='',$cfg = array(), $sitename='') {
- global $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_mail_type = $cfg['mail_type']; //郵件發送模式
- $mail = $cfg;
- } else {
- $adminemail = $mail_id;
- $mail_type = $mail_type; //郵件發送模式
- #連接埠,郵件頭的分隔符號,收件者位址中包含使用者名稱
- $mail= Array (
- 'mailsend' => 2,
- 'maildelimiter' => 1,
- 'mailusername' => 1,
- 'server' => $mail_server, #伺服器
- 'port' => $mail_port, #連接埠
- 'auth' => $mail_id, #作者
- 'from' => $mail_id, #發信者
- 'auth_username' => $mail_id, #賬號
- 'auth_password' => $mail_pw #密碼
- );
- }
- //mail 傳送模式
- if(!$mail_type) {
- $headers = 'MIME-Version: 1.0' . "rn";
- $headers .= 'Content-type: text/html; charset ='.$db_charset.'' . "rn";
- $headers .= 'From: '.$sitename.' ' . "rn";
- 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'] ? $mail['port'] : 25;
- $mail['mailsend'] = $mail['mailsend'] ? $mail['mailsend'] : 1;
- //發信者
- $email_from = $from == '' ? '=? '.$db_charset.'?B?'.base64_encode($sitename)."?= " : (preg_match('/^(. ?) $/', $from, $mats) ? '=?'.$db_charset.'?B?'.base64_encode($mats[1])."?= " : $from);
- / /收信人
- $email_to = preg_match('/^(. ?) $/',$toemail, $mats) ? ($mailusername ? '=?'.$db_charset.'?B ?'.base64_encode($mats[1])."?= " : $mats[2]) : $toemail;;
- //郵件標題
- $email_subject = '= ?'.$db_charset.'?B?'.base64_encode(preg_replace("/[r|n]/", '', $subject.'--'.$db_wwwname)).'?=';
- //郵件內容
- $message = $message."Published at ".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 = "From: $email_from{$maildelimiter}X-Priority: 3{$maildelimiter}X-Mailer: abaoei cms {$maildelimiter}MIME-Version: 1.0{$maildelimiter}Content-type: text/html; charset=".$db_charset."{$maildelimiter}Content-Transfer-Encoding: base64{$maildelimiter}";
-
- if(!$fp = fsockopen($mail['server'], $mail['port'], $errno, $errstr, 30)) {
- self::runlog('SMTP', "($mail[server]:$mail[port]) CONNECT - Unable to connect to the SMTP server", 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) != '-' || empty(substr($lastmessage, 3, 1) != '-' || empty(substr($lastmessage, 3, 1) != '-' || empty(substr($lastmessage, 3, 1) != '-' || empty(substr($lastmessage, 3, 1) != '-' || empty( $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) ;
- return false;
- }
-
- fputs($fp, base64_encode($mail['auth_username'])."rn");
- $lastmessage = fgets($fp, 512 ) ;
- if(substr($lastmessage, 0, 3) != 334) {
- self::runlog('SMTP', "($mail[伺服器]:$mail[連接埠]) 使用者名稱- $lastmessage ", 0);
- return false;
- }
-
- fputs($fp, base64_encode($mail['auth_password'])."rn");
- $ lastmessage = fgets( $fp, 512);
- if(substr($lastmessage, 0, 3) != 235) {
- self::runlog('SMTP', "($mail[伺服器]:$ mail[連接埠] ) 密碼- $lastmessage", 0);
- 回傳false;
- }
-
- $email_from = $mail['from'];
- }
-
-
- fputs($ fp, "郵件寄件人: .*/", "\1", $email_from).">rn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0, 3) != 250) {
- fputs($fp, "mail來自: .*/", "\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: .*/", "\1" , $toemail).">rn");
- $lastmessage = fgets($fp, 512);
- if(substr($lastmessage, 0, 3) != 250) {
- fputs( $ fp, "RCPT TO: .*/", "\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[伺服器]:$mail[連接埠]) DATA - $lastmessage", 0);
- 回傳false;
- }
-
- $headers .= '訊息ID: {$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);
- $lastmessage = fgets($fp , 512);
- if(substr($lastmessage, 0, 3) != 250) {
- self::runlog('SMTP', "($mail[伺服器]:$mail[連接埠]) END - $lastmessage", 0 );
- }
- fputs($fp, "QUITrn");
- return true;
- }
} //emailui::sendmail(' admin33@163.com' , '你好哦', '非常感謝');
複製代碼
|