'localhost', 'port' => 25, 'user' => '', 'pass' => '', 'secure' => '', 'debug' => false, ), ( ! empty($config['smtp']) ? $config['smtp'] : [])); $smtp['host'] = config::sysAdmin('mail.smtp.host', $smtp['host'], TYPE_NOTAGS); $smtp['port'] = config::sysAdmin('mail.smtp.port', $smtp['port'], TYPE_UINT); $smtp['user'] = config::sysAdmin('mail.smtp.user', $smtp['user'], TYPE_NOTAGS); $smtp['pass'] = config::sysAdmin('mail.smtp.pass', $smtp['pass'], TYPE_PASS); $smtp['secure'] = config::sysAdmin('mail.smtp.secure', $smtp['secure'], TYPE_NOTAGS); $config['smtp'] = $smtp; $config = bff::filter('mail.config', $config); $this->From = $config['noreply']; $this->FromName = $config['fromname']; $this->CharSet = 'UTF-8'; $this->XMailer = ' '; $this->Host = ''; $this->Hostname = SITEHOST; # HTML message $this->isHTML(true); # Default method: mail $this->isMail(); # Errors: EN => RU if (bff::locale()->getCurrentLanguage() === 'ru') { $this->setLanguage('ru'); } switch ($config['method']) { case 'sendmail': { $this->isSendmail(); } break; case 'smtp': { $this->isSMTP(); $this->SMTPKeepAlive = true; $this->SMTPAutoTLS = false; if (! empty($smtp['secure'])) { $this->SMTPSecure = strval($smtp['secure']); } $this->Host = $smtp['host'] . ':' . intval($smtp['port']); $this->SMTPAuth = !empty($smtp['user']); if ($this->SMTPAuth) { $this->Username = $smtp['user']; $this->Password = $smtp['pass']; } $smtpDebug = config::get('smtp.debug', false); if (! empty($smtp['debug']) || ! empty($smtpDebug)) { $this->SMTPDebug = ! empty($smtpDebug) ? 4 : 2; $this->Debugoutput = ! empty($smtpDebug) ? $smtpDebug : (is_string($smtp['debug']) ? $smtp['debug'] : 'error_log'); } } break; } } /** * Отправка сообщения * @return bool */ public function send() { # Send $timeStart = microtime(true); try { $result = parent::send(); } catch (PHPMailer\Exception $e) { throw new PHPMailer\Exception($e->getMessage(), $e->getCode(), $e); } $timeFinish = microtime(true) - $timeStart; # Hooks if (bff::hooksAdded('mail.sended')) { bff::hook('mail.sended', array( 'to' => array_keys($this->getAllRecipientAddresses()), 'subject' => $this->Subject, 'body' => $this->Body, 'from' => $this->From, 'fromName' => $this->FromName, 'result' => $result, 'time' => $timeFinish, ), $this); } # Result return $result; } }