From 506b819e1f43709315a95e1d2a236a60ee7023ff Mon Sep 17 00:00:00 2001 From: itchief Date: Mon, 8 May 2023 20:07:42 +1000 Subject: [PATCH] fix small error and setting up PHPMailer logging to a file --- feedback/form-processing.php | 11 ++++++++--- feedback/js/form-processing.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/feedback/form-processing.php b/feedback/form-processing.php index 97a0057..89a2785 100644 --- a/feedback/form-processing.php +++ b/feedback/form-processing.php @@ -2,7 +2,7 @@ /* * Форма обратной связи (https://itchief.ru/lessons/php/feedback-form-for-website) - * Copyright 2016-2022 Alexander Maltsev + * Copyright 2016-2023 Alexander Maltsev * Licensed under MIT (https://github.com/itchief/feedback-form/blob/master/LICENSE) */ @@ -171,7 +171,7 @@ function itc_log($message) } use PHPMailer\PHPMailer\PHPMailer; -//use PHPMailer\PHPMailer\SMTP; +use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; require 'vendor/phpmailer/phpmailer/src/Exception.php'; @@ -199,7 +199,12 @@ function itc_log($message) } else { $body = str_replace('%attachs%', '', $body); } - $mail = new PHPMailer(); + $mail = new PHPMailer(true); + $mail->SMTPDebug = 2; + $mail->Debugoutput = function($str, $level) { + $file = __DIR__ . '/logs/smtp_' . date('Y-m-d') . '.log'; + file_put_contents($file, gmdate('Y-m-d H:i:s'). "\t$level\t$str\n", FILE_APPEND | LOCK_EX); + }; try { //Server settings $mail->isSMTP(); diff --git a/feedback/js/form-processing.js b/feedback/js/form-processing.js index d0b779e..6b50831 100644 --- a/feedback/js/form-processing.js +++ b/feedback/js/form-processing.js @@ -147,7 +147,16 @@ class ItcSubmitForm { return; } - this._elForm.querySelector('.form-error').classList.remove('form-error_hidden'); + this._elForm.querySelector('.form-error').classList.add('form-error_hide'); + // this._elForm.querySelector('.form-error').classList.remove('form-error_hidden'); + + if (!Object.keys(data['errors']).length) { + this._elForm.querySelector('.form-error').textContent = 'При отправке сообщения произошла ошибка. Пожалуйста, попробуйте ещё раз позже.'; + } else { + this._elForm.querySelector('.form-error').textContent = 'В форме содержатся ошибки!'; + } + + this._elForm.querySelector('.form-error').classList.remove('form-error_hide'); // выводим ошибки for (let key in data['errors']) {