/** * 单例 * * @return \G\Conf */ public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self(); } return self::$instance; }
/** * send mail by system built-in sendmail commands * @para string $to, receiver's email address * @para string $subject, email's subject * @para string $body, message body * return array(0=>true|false, 1=>array('error'=>'...')); */ function sendMail($to, $subject, $body, $from = '', $local = 0) { $rtnarr = array(); if ($local == 0) { $from = $from == '' ? $_CONFIG['adminmail'] : $from; $mailstr = 'To:' . $to . '\\n'; $mailstr .= 'Subject:' . $subject . '\\n'; $mailstr .= 'Content-Type:text/html;charset=UTF-8\\n'; $mailstr .= 'From:' . $from . '\\n'; $mailstr .= '\\n'; $mailstr .= $body . '\\n'; $tmpfile = "/tmp/" . GConf::get('agentalias') . ".user.reg.mail.tmp"; system('/bin/echo -e "' . $mailstr . '" > ' . $tmpfile); system('/bin/cat ' . $tmpfile . ' | /usr/sbin/sendmail -t &'); $rtnarr[0] = true; } else { if ($local == 1) { global $_CONFIG; include $_CONFIG['appdir'] . "/mod/mailer.class.php"; $_CONFIG['mail_smtp_server'] = "smtp.163.com"; $_CONFIG['mail_smtp_username'] = "******"; $_CONFIG['mail_smtp_password'] = "******"; $_CONFIG['isauth'] = true; $_CONFIG['mail_smtp_fromuser'] = $_CONFIG['mail_smtp_username']; $mail = new Mailer($_CONFIG['mail_smtp_server'], 25, $_CONFIG['isauth'], $_CONFIG['mail_smtp_username'], $_CONFIG['mail_smtp_password']); $mail->debug = true; $from == '' ? 'bangco@' . $_CONFIG['agentname'] : $from; if ($_CONFIG['isauth']) { $from = $_CONFIG['mail_smtp_fromuser']; } #print __FILE__.": from:$from"; $rtnarr[0] = $mail->sendMail($to, $from, $subject, $body, 'HTML'); } } return $rtnarr; }