File: //proc/thread-self/root/home/retile.ru/public_html/catalog/controller/feedback/feedback.php
<?php
class ControllerFeedbackFeedback extends Controller {
/* ============================================================
ФУНКЦИЯ ОТПРАВКИ ПИСЬМА ДЛЯ POSTONE и POSTTWO
============================================================ */
private function sendMailUnified($subject_name, $subject_title) {
// === Формируем HTML-тело письма ===
$message = "";
foreach ($this->request->post as $key => $val) {
if ($key == 'name' || $key == 'phone' || $key == 'captcha' || $key == 'Политика принята') continue;
$message .= "<strong>" . $key . ":</strong> " . nl2br($val) . "<br>";
}
// === Инициализация OpenCart Mail ===
$mail = new Mail($this->config->get('config_mail_engine'));
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
// === Отправитель ===
$from_email = $this->config->get('config_mail_smtp_username');
// === Получатели ===
$alert_list = [];
// config_mail_alert_email (через запятую)
$alert_emails = $this->config->get('config_mail_alert_email');
if (!empty($alert_emails)) {
foreach (explode(',', $alert_emails) as $e) {
$e = trim($e);
if (filter_var($e, FILTER_VALIDATE_EMAIL)) {
$alert_list[] = $e;
}
}
}
// главный email магазина
$main_email = $this->config->get('config_email');
if (filter_var($main_email, FILTER_VALIDATE_EMAIL)) {
$alert_list[] = $main_email;
}
// удалить дубликаты
$alert_list = array_unique($alert_list);
// === Рассылка каждому адресату ===
foreach ($alert_list as $email_to) {
$mail->setTo($email_to);
$mail->setFrom($from_email);
$mail->setSender(html_entity_decode($subject_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject_title, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($message);
$mail->send();
}
return true;
}
/* ============================================================
P O S T O N E
============================================================ */
public function postone() {
$json = [];
/* ---------- Upload ---------- */
$allowed = ['png','jpg','gif','svg','zip','txt','doc','docx','cdr','ai','eps'];
if (isset($_FILES['upl']) && $_FILES['upl']['error'] === 0) {
$extension = strtolower(pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION));
if (!in_array($extension, $allowed)) {
exit('{"status":"error"}');
}
if (move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/' . $_FILES['upl']['name'])) {
exit('{"status":"success"}');
}
}
/* ---------- POST из php://input ---------- */
$raw = file_get_contents('php://input');
foreach (explode('&', $raw) as $pair) {
if (strpos($pair, '=') !== false) {
list($k, $v) = explode('=', $pair);
$k = urldecode($k);
$v = urldecode($v);
if (!isset($_POST[$k])) {
$this->request->post[$k] = $v;
}
}
}
/* ---------- Валидация ---------- */
if (mb_strlen($this->request->post['Имя']) < 2) {
$json['error']['Имя'] = 'Неправильно: Имя';
}
if (mb_strlen($this->request->post['Телефон']) < 8) {
$json['error']['Телефон'] = 'Неправильно: Телефон';
}
if (mb_strlen($this->request->post['Сообщение']) < 5) {
$json['error']['Сообщение'] = 'Неправильно: Сообщение';
}
/* ---------- Антибот ---------- */
if (!empty($this->request->post['name']) || !empty($json['error'])) {
die('BOTS!');
}
/* ---------- Отправка письма ---------- */
$this->sendMailUnified(
'Бесплатная консультация',
'Запрос консультации с сайта retile.ru'
);
$json['status'] = 'Success';
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/* ============================================================
P O S T T W O
============================================================ */
public function posttwo() {
$json = [];
/* ---------- Upload ---------- */
$allowed = ['png','jpg','gif','svg','zip','txt','doc','docx','cdr','ai','eps'];
if (isset($_FILES['upl']) && $_FILES['upl']['error'] === 0) {
$extension = strtolower(pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION));
if (!in_array($extension, $allowed)) {
exit('{"status":"error"}');
}
if (move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/' . $_FILES['upl']['name'])) {
exit('{"status":"success"}');
}
}
/* ---------- POST из php://input ---------- */
$raw = file_get_contents('php://input');
foreach (explode('&', $raw) as $pair) {
if (strpos($pair, '=') !== false) {
list($k, $v) = explode('=', $pair);
$k = urldecode($k);
$v = urldecode($v);
if (!isset($_POST[$k])) {
$this->request->post[$k] = $v;
}
}
}
/* ---------- Валидация ---------- */
if (mb_strlen($this->request->post['Ваше имя']) < 2) {
$json['error']['Ваше имя'] = 'Неправильно: Ваше имя';
}
if (mb_strlen($this->request->post['Телефон']) < 8) {
$json['error']['Телефон'] = 'Неправильно: Телефон';
}
/* ---------- Антибот ---------- */
if (!empty($this->request->post['phone']) || !empty($json['error'])) {
die('BOTS!');
}
/* ---------- Отправка письма ---------- */
$this->sendMailUnified(
'Коммерческое предложение',
'Коммерческое предложение с сайта retile.ru'
);
$json['status'] = 'Success';
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}