How to send a file from the form without reloading the page?

The crux of the matter:
There on the page form, not even form, but simply: "select file" "send". I want to get this file on mail. I found one solution that seems to work but reboots the page and no message after successful submission. I want to find a way to implement a file upload into my Inbox without reloading the page. well, display a message about successful sending. In Google there are several solutions, but there is a download of a file on the server (here).

Maybe there's someone ready-made solution? Preferably with an example of all necessary files
July 2nd 19 at 17:52
2 answers
July 2nd 19 at 17:54
how do you file in the mail is sent with page reload?OO
inside the pages:
function show_form()
{ ?> complete_mail function() {
require 'class.phpmailer.php';

$mail = new PHPMailer();
$mail->From = ''; // from whom, for example the email address of your website
$mail->FromName ='; // from whom, the name.
$mail->AddAddress('', 'Name'); // to whom? Your mail, Name
$mail->IsHTML(true); // format the HTML mails
$mail->Subject = "Subject"; // subject

// if file, then attach it to the letter

if(isset($_FILES['upl'])) {
if($_FILES['upl']['error'] == 0){
$mail->List($_FILES['upl']['tmp_name'], $_FILES['upl']['name']); } }

$mail->Body = $mess;
// send our email
if (!$mail->Send()) die ('Mailer Error: '.$mail->ErrorInfo);

if (!empty($_POST['submit'])) complete_mail();
else show_form();

and there's another php file separately (class.phpmailer.php) - kyleigh.Schill commented on July 2nd 19 at 17:57
you likewise, the file send to the server. - albertha.Medhur commented on July 2nd 19 at 18:00
I meant that the example task is simply to load the file on the server in a folder. And I need it to send in the mail - kyleigh.Schill commented on July 2nd 19 at 18:03
July 2nd 19 at 17:56
Above correctly write that in any case, the load first goes to the server and then sending mail.
So the page is not reloaded AJAX to help.

Find more questions by tags AJAXjQueryHTMLPHP