How to glue 2 of the script?

<form id="formss1" method="POST" action="javascript:void(0);" onsubmit="ajaxsend_formss('1');" enctype="multipart/form-data">
 <input type="text" name="name" required placeholder>
 <input type="text" name="asd" required placeholder>
 <input type="text" name="rty" required placeholder>
 <input type="text" name="hfg" required placeholder>
 <input type="text" name="nvb" required placeholder>
 <input type="file" name="fileFF[]" multiple id="fileFF" class="w100">
 <button type="submit">Leave request on</button>
 </form>

The initial JS
the <script>
 document.getElementById('formss1').addEventListener('submit', function(evt){
 var http = new XMLHttpRequest(), f = this;
evt.preventDefault();
 http.open("POST", "mail2.php", true);
 location.href = "#callme1";
 http.onerror = function() {
 alert('Sorry, no data was passed');
}
 http.send(new FormData(f));
 }, false);
 </script>

It is necessary to stick:
$(function(){
$("input[type='submit']").click(function(){
 var $fileUpload = $("input[type='file']");
 if (parseInt($fileUpload.get(0).files.length)>2){
 alert("You can only upload a maximum of 2 files");
}
 }); 
});

<?php
 $to = "mail@mail.ru";
 $subject = "online Application";
 $from ="From ".$_SERVER['HTTP_HOST'];
 $message = .$_POST['name'] .$_POST['dsa'] .$_POST['dsad'] .$_POST['dasd'] .$_POST['dasd'];
 $boundary = md5(date('r', time()));
 $filesize = ";
 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "From:" . $from . "\r\n";
 $headers .= "Reply-To:" . $from . "\r\n";
 $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$message="
Content-Type: multipart/mixed; boundary=\"$boundary\"

--$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit

$message";
 for($i=0;$i<count($_FILES['fileFF']['name']);$i++) {
 if(is_uploaded_file($_FILES['fileFF']['tmp_name'][$i])) {
 $attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'][$i])));
 $filename = $_FILES['fileFF']['name'][$i];
 $filetype = $_FILES['fileFF']['type'][$i];
 $filesize += $_FILES['fileFF']['size'][$i];
$message.="

--$boundary
Content-Type: \"$filetype\" name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$filename\"

$attachment";
}
}
$message.="
--$boundary--";

 mail($to, $subject, $message, $headers);
?>
June 27th 19 at 15:32
1 answer
June 27th 19 at 15:34
it is not clear who should do it. standard means JS is not suitable?
var script= document.createElement('script');
script.innerHTML = /the script/;
document.body.appendChild(script);

Find more questions by tags JavaScript