The attached file is not sent. From the data forms come, but not the file itself. How do I pass the $_FILES variable to the AJAX ???
HTML forms
<form action="" name="send-form" id="send-form" enctype="multipart/form-data"> <div class="input-line"> <input type="text" required name="email" placeholder=""> </div> <div class="input-line"> <input type="text" required name="search-name" placeholder=""> </div> <div class="input-line"> <input type="file" id="photo-file" name="photo" placeholder=""> </div> </form> Js
$('#send-form').submit(function () { var form_data = $(this).serialize(); $.ajax({ type: "POST", url: "mail.php", data: form_data, success: function() { } }); return false; }); Php handler
$mail->isSMTP(); $mail->Host = 'smtp.mail.ru'; $mail->SMTPAuth = true; $mail->Username = ''; $mail->Password = ''; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; //Recipients $mail->setFrom(''); $mail->addAddress($_POST['email']); //Attachments $mail->addAttachment($_FILES["photo"]["tmp_name"],$_FILES["photo"]["name"]); //Content $mail->isHTML(true); $mail->Subject = 'Заявка c сайта'; $mail->Body = '<html> <head> <title>'.$subject.'</title> </head> <body> <p>Почта для связи: '.$_POST['email'].'</p> <p>Имя для поиска: '.$_POST['search-name'].'</p> </body> </html>'; $mail->AltBody = ''; $mail->send(); echo 'Сообщение успешно отправлено'; } catch (Exception $e) { echo 'Не удалось отправить сообщение ', $mail->ErrorInfo; }