/** * 发送邮件 * * @param string $address 收件人,多个用 ";" 分开 * @param string $subject 主题 * @param string $body 内容 * @param string $attachment 附件文件,多个用 ";" 分开,要用绝对路径,如 "/tmp/a.zip;/tmp/b.zip" * @return unknown */ public function send($address, $subject, $body, $attachment = '') { $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; $mail->SetLanguage('zh_cn'); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->SMTPAuth = $this->_config['auth']; $mail->Host = $this->_config['host']; $mail->Port = $this->_config['port']; $mail->Username = $this->_config['username']; $mail->Password = $this->_config['password']; $mail->SetFrom($this->_config['from'], $this->_config['fromname']); $mail->Subject = $subject; $mail->MsgHTML($body); $mail->SMTPSecure = $this->_config['secure']; // 收件人 $addrArr = explode(';', $address); foreach ($addrArr as $addr) { $mail->AddAddress($addr); } // 附件 if ($attachment != '') { $attaArr = explode(';', $attachment); foreach ($attaArr as $file) { $mail->AddAttachment($file); } } if (!$this->debug) { // 发送 if (!$mail->Send()) { $ret = $mail->ErrorInfo; } else { $ret = true; } } else { // 写日志 $message = $subject . PHP_EOL . $body; QP_Sys::log($message, 'email'); $ret = true; } return $ret; }
/** * 发送通知 * * @param unknown_type $receiver 接收者ID,多个ID用","连接,如:"yuanwei1,guoyu" * @param unknown_type $msg 消息内容 * @param unknown_type $url 点击消息所打开的URL * @param unknown_type $title 标题 * @param unknown_type $delaytime 消息提醒框的停留时间(毫秒),0表示不自动消失。 */ public static function send($receiver, $msg, $url, $title = 'QuickBug Notify', $delaytime = 0) { $rtxCfg = QP_Sys::config('sysconfig.rtx'); // RTX网关只支持 GBK 的编码 $msg = sprintf("[%s|%s]", $msg, $url); $msg = mb_convert_encoding($msg, 'gbk', 'utf-8'); $title = mb_convert_encoding($title, 'gbk', 'utf-8'); // 组合参数 $params = implode('&', array('title=' . urlencode($title), 'receiver=' . $receiver, 'msg=' . urlencode($msg), 'delaytime=' . $delaytime)); $url = sprintf("http://%s:%d/sendnotify.cgi?%s", $rtxCfg['host'], $rtxCfg['port'], $params); if (!self::$debug) { // 发送请求 if (function_exists('curl_init')) { QP_Sys::load('curl')->set(array('port' => $rtxCfg['port'], 'timeOut' => 5))->get($url); } else { @file_get_contents($url); } } else { // 写日志 QP_Sys::log($url, 'rtx'); } }
/** * 数据库连接或查询错误处理 * * @param string $errorMsg */ protected function _DBError($errorMsg) { // 如果显示错误则直接抛出异常 if ($this->_showError) { throw new QP_Exception($errorMsg, QP_Exception::EXCEPTION_DB_ERROR); } else { // 否则就写日志 QP_Sys::log($errorMsg, 'db'); } }