- 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 _type = $cfg [' Mail_type ']; Mail delivery mode
- $mail = $cfg;
- } else {
- $adminemail = $mail _id;
- $mail _type = $mail _type; Mail delivery mode
- #端口, the delimiter for the message header, which contains the user name in the recipient address
- $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 Send mode
- if (! $mail _type) {
- $headers = ' mime-version:1.0 '. "\ r \ n";
- $headers. = ' content-type:text/html; Charset= '. $db _charset. "\ r \ n";
- $headers. = ' from: '. $sitename. ' < '. $from. ' > '. "\ r \ n";
- Mail ($toemail, $subject, $message, $headers);
- return true;
- }
- Delimiter for message headers
- $maildelimiter = $mail [' maildelimiter '] = = 1? "\ r \ n": ($mail [' maildelimiter '] = = 2? "\ r": "\ n");
- The recipient address contains the user name
- $mailusername = Isset ($mail [' mailusername '])? $mail [' Mailusername ']: 1;
- Port
- $mail [' port '] = $mail [' Port ']? $mail [' Port ']: 25;
- $mail [' mailsend '] = $mail [' MailSend ']? $mail [' MailSend ']: 1;
- Sender
- $email _from = $from = = "? '=?'. $db _charset. '? B? '. Base64_encode ($sitename). "? = < ". $adminemail." > ": (Preg_match ('/^ (. +?) \< (. +?) \>$/', $from, $mats)? '=?'. $db _charset. '? B? '. Base64_encode ($mats [1]). "? = < $mats [2]> ": $from);
- The addressee.
- $email _to = Preg_match ('/^ (. +?) \< (. +?) \>$/', $toemail, $mats)? ($mailusername? '=?'. $db _charset. '? B? '. Base64_encode ($mats [1]). "? = < $mats [2]> ": $mats [2]): $toemail;;
- Message header
- $email _subject = ' =? '. $db _charset. '? B? '. Base64_encode (Preg_replace ("/[\r|\n]/", "', $subject. '--". $db _wwwname)). '? =';
- Message content
- $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", "\ r \ n", Str_replace ("\ r", "\ n", Str_replace ("\ r \ n", "\ n") , Str_replace ("\n\r", "\ 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 '). "uchome\r\n");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = && 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 ($lastmessage)) {
- Break
- }
- $lastmessage = fgets ($FP, 512);
- }
- if ($mail [' auth ']) {
- Fputs ($fp, "AUTH login\r\n");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 334) {
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) AUTH login-$lastmessage", 0);
- return false;
- }
- Fputs ($fp, Base64_encode ($mail [' auth_username ']). " \ r \ n ");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 334) {
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) username-$lastmessage", 0);
- return false;
- }
- Fputs ($fp, Base64_encode ($mail [' Auth_password ']). " \ r \ n ");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 235) {
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) password-$lastmessage", 0);
- return false;
- }
- $email _from = $mail [' from '];
- }
- Fputs ($fp, "MAIL from: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $email _from)." >\r\n ");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 250) {
- Fputs ($fp, "MAIL from: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $email _from)." >\r\n ");
- $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)." >\r\n ");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 250) {
- Fputs ($fp, "RCPT to: <". Preg_replace ("/.*\< (. +?) \>.*/"," \\1 ", $toemail)." >\r\n ");
- $lastmessage = fgets ($FP, 512);
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) RCPT to-$lastmessage", 0);
- return false;
- }
- Fputs ($fp, "data\r\n");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 354) {
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) data-$lastmessage", 0);
- return false;
- }
- $headers. = ' Message-id: < '. Gmdate (' Ymdhs '). SUBSTR (MD5 ($email _message.microtime ()), 0, 6). Rand (100000, 999999). ' @ '. $_server[' Http_host ']. " >{$maildelimiter} ";
- Fputs ($FP, "Date:". Gmdate (' R '). " \ r \ n ");
- Fputs ($FP, "to:". $email _to. " \ r \ n ");
- Fputs ($FP, "Subject:". $email _subject. " \ r \ n ");
- Fputs ($FP, $headers. " \ r \ n ");
- Fputs ($fp, "\r\n\r\n");
- Fputs ($fp, "$email _message\r\n.\r\n");
- $lastmessage = fgets ($FP, 512);
- if (substr ($lastmessage, 0, 3)! = 250) {
- Self::runlog (' SMTP ', "($mail [Server]: $mail [port]) end-$lastmessage", 0);
- }
- Fputs ($fp, "quit\r\n");
- return true;
- }
- }
- Emailui::sendmail (' admin33@163.com ', ' Hello Oh ', ' thank you ');
Copy Code
|