How to attach a file to the Ajax form?

Good day, there is a standard form, please tell me as I need to add so you can send files in the form. (The form itself is working - all good)
---
the <script>
 SendPost1 function() {
jQuery.ajax({
 type: "GET",
 url: "/send.php",
 data: jQuery("#forma2").serialize(),
 success: function(html) {
jQuery(".wr").empty();
 jQuery(".wr").append("<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button><h2 style='margin-top: 20px; color: #fff;'><center>Your message was successfully sent. the <br>Manager will contact you within 10 minutes</center></h2>");
}
});
 } 
</script>
 <form action="" id="forma2" class="wr">
 <h3 class="black">to <span class="yellow">Advice</span></h3>
 <input type="text" name="name" placeholder="Enter name" required="">
 <input type="text" name="tel" placeholder="Enter phone" required="">
 <input name="file" value="1" size="40" type="file" />
 <button class="btn btn-default btn-form-2" type="button" onclick="SendPost1();"> SEND </button>
 </form>

send.php
<?php
 //Get data from global $_GET variable, so as we pass data by GET method
 $name = $_GET['name']; // Pulls the name into a variable
 $tel = $_GET['tel']; // Pulls the mail into a variable
 $k_form = $_GET['k_form']; // Pulls the mail into a variable
 $email = $_GET['email']; // Pulls the mail into a variable
 $file = $_GET['file']; // Pulls the mail into a variable
 $comment = $_GET['comment']; // Pulls the mail into a variable
 $price = $_GET['price']; // Pulls the mail into a variable
 $message = "<strong>Name: </strong> $name <br> <strong>Phone:</strong> $tel <br> <strong>Email</strong> $email <br> <strong>File</strong> $file <br> <strong>Review: </strong> $comment <br> <strong>What form</strong> $k_form"; // Generated message that is sent in the mail
 $to = 'valera@gmail.com'; // Set recipient
 $from = "Al"; // From whom the letter
 $subject = "Al Application form from website"; // Set email subject
 $headers = "From: $from\r\nReply-To: $to\r\nContent-type: text/html; charset=utf-8\r\n"; // form the header of the letter (with incorrect formation can break the encoding, etc.)
 if (mail($to, $subject, $message, $headers)) { // using the function mail, send a message, checking we appreciate it!
 echo "<p>Message successfully sent</p>"; // Upload successful
}
 else {
 echo "<p>something went not as planned</p>"; // the Letter went
}
?>
March 23rd 20 at 19:29
3 answers
March 23rd 20 at 19:31
Good afternoon.
How to upload image to the server via AJAX?

PS
By the way, why send the form method is $_GET?
Then, You need to attach a picture to a message? Why is the issue a word about it?
If we need to attach a file to a message, then the server, use PHPMailer, it's easier to attach a file, and guaranteed will work on the hosting.
Otherwise, everything is unchanged, as in the example on the link.
I need the image as file! - adrienne.Pacocha commented on March 23rd 20 at 19:34
@adrienne.Pacocha, what's the difference? the image is the same file. - reid.Ziemann76 commented on March 23rd 20 at 19:37
@reid.Ziemann76, Yes, but doesn't work (( it has all the brains merged his ((( don't know somewhere ready-made solution to sending a file by email ? - adrienne.Pacocha commented on March 23rd 20 at 19:40
@adrienne.Pacocha, I already gave the finished solution upload file to the server, as Your question is asked, so
How to attach a file to the Ajax form?

The code in the example on the link sends a file using ajax to the server.
don't know somewhere ready-made solution with sending a file to the mail

In a PostScript to his answer, I wrote that it is necessary to use for normal message sending.
Using PHPMailer you can attach a file to the message. This is the easiest way. Read the documentation for PHPMailer, everything is available painted.
If it doesn't work, then a new question about this effect:
How to send email with attachment in php?
- reid.Ziemann76 commented on March 23rd 20 at 19:43
@adrienne.Pacocha, and yet, You never get a file on server using $_GET or $_POST, there is a special $_FILES array. - reid.Ziemann76 commented on March 23rd 20 at 19:46
@adrienne.Pacocha, and again
Yes - but you're not

What does not work? Errors, warnings? Where the code does not work for You? - reid.Ziemann76 commented on March 23rd 20 at 19:49
March 23rd 20 at 19:33
Found, tried - does not work! - adrienne.Pacocha commented on March 23rd 20 at 19:36
@adrienne.Pacocha, bad tried! For the form attribute enctype="multipart/form-data" added?

And forms date created as in the example written instead of serialize from jquery?
I somehow doubt it - Amparo.Gleason commented on March 23rd 20 at 19:39
@adrienne.Pacocha, what exactly doesn't work? - reid.Ziemann76 commented on March 23rd 20 at 19:42
@Amparo.Gleason, created (((
---
For example, my forms you can explain ? - adrienne.Pacocha commented on March 23rd 20 at 19:45
@reid.Ziemann76, don't know how my submission form to append the file upload on the Internet and have tried a lot of examples nichgeo not working - adrienne.Pacocha commented on March 23rd 20 at 19:48
March 23rd 20 at 19:35
Firstly, the form's method must be POST
The second in any material from search gugula described in detail how and what to do in particular shows the required attributes for sending files:processData: false, contentType: false, however, to compare the 3 lines you lazy.
Thirdly, in the handler, respectively, all parameters sent to the server will be $_POST and the file will be in a separate global array $_FILES.
If you do not understand - ask on freelancing, otherwise this information should be sufficient for your needs.

Find more questions by tags jQueryJavaScriptPHP