Дополню JS, дал не полностью.
if (field.type !== 'file') {
if (field.type == 'checkbox') {
message += `<p><b>${field.dataset.field} :</b> ${(field.checked?'Да':'Нет')}</p>`;
}else{
message += `<p><b>${field.dataset.field} :</b> ${field.value}</p>`;
}
}
};
try {
let data = new FormData();
const fileInput = Array.from(fileds).find(el => el.type === 'file');
if (fileInput) {
const fileInputFiles = fileInput.files;
for (var i = 0; i < fileInputFiles.length; i++) {
var file = fileInputFiles[i];
// Add the file to the request.
data.append('files[]', file, file.name);
}
}
data.append('message', message);