Why not come attached file to e-mail?

Hello! Why not come attachments (pictures) to the letter? The main data come type the name,email,phone ,etc., and the attached file there.

Are of the form:
<form action class="slider-form" id="formMain" method="post" name="formMain">
<input class="w100 border" id="nameFF" name="nameFF" placeholder="for example, Ivan Ivanovich Ivanov" required type="text" x-autocompletetype="name">
<input class="w100 border" id="contactFF" name="contactFF" placeholder="e.g. ivan@yandex.ru" required type="email" x-autocompletetype="email">
<label for="fileFF">Attach file:</label>
<input class="w100" id="fileFF" multiple="multiple" name="fileFF[]" type="file">
<input class="button-submit" id="button-post" type="button" value="Send">
</form>


Next is the type of Ajax:
$("#button-post").click(function () {
$.ajax({
 url: "/feedback/post.php",
 type: "POST",
 dataType: "html",
 data: jQuery("#"+formMain).serialize(), 
 success: function(response) {
 document.getElementById(result_id).innerHTML = response;
 }, 
 }); 

 }


Next php:
<?php
if (isset ($_POST['contactFF'])) {
 $to = "dadada@mail.ru"; // change to your email address
 $from = $_POST['contactFF'];
 $subject = "Completed contact form ".$_SERVER['HTTP_REFERER'];
 $message = "Name: ".$_POST['nameFF']."\nEmail: ".$"from"."\nIP: ".$_SERVER['REMOTE_ADDR'];
 $boundary = md5(date('r', time()));
 $filesize = ";
 $headers = "MIME-Version: 1.0\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--";

 if ($filesize < 10000000) { // check for the total size of all files. Many mail services do not accept attachments larger than 10 MB
 mail($to, $subject, $message, $headers);
 echo $_POST['nameFF'].', Your message has been sent, thanks!';
 } else {
 echo 'Sorry, your email failed. The size of all files exceeds 10 MB.';
}
}
?>

What's wrong here? Why the attached file doesn't appear in the letter?
Thanks in advance.

PS can one example is. But there is a problem....I specifically did not use type="submit" because I have the visual editor is buggy))))Brad,but still...
July 9th 19 at 10:04
1 answer
July 9th 19 at 10:06
And what do you think? Files via AJAX will not transfer, only text.
Search for AJAX file uploading, there are used crutches, frame type

Find more questions by tags AJAXHTMLjQueryPHPWeb Development