<form id="formss1" method="POST" action="javascript:void(0);" onSubmit="ajaxsend_formss('1');" enctype="multipart/form-data">
<input type="text" name="name" placeholder="" required/>
<input type="text" name="asd" placeholder="" required/>
<input type="text" name="rty" placeholder="" required/>
<input type="text" name="hfg" placeholder="" required/>
<input type="text" name="nvb" placeholder="" required/>
<input type="file" name="fileFF[]" multiple id="fileFF" class="w100">
<button type="submit">Оставить заявку на сайте</button>
</form>
Начальный JS
<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('Извините, данные не были переданы');
}
http.send(new FormData(f));
}, false);
</script>
Надо засунуть:
$(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 = "Заявка онлайн";
$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);
?>