Skip to content

Commit

Permalink
fix small error and setting up PHPMailer logging to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
itchief committed May 8, 2023
1 parent 84d3cec commit 506b819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 8 additions & 3 deletions feedback/form-processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion feedback/js/form-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down

0 comments on commit 506b819

Please sign in to comment.