Answer the question
In order to leave comments, you need to log in
How to accept files sent by ajax via formData on the server side?
given a form with an input with the multiple attribute:
<form>
<input type="file" name="file" multiple="multiple">
</form>
$('form').submit(function(){
$.ajax({
type: "POST",
url: "phpmailer/mail.php",
data: new FormData( this ),
processData: false,
contentType: false,
success: function() {
}
return false;
});
<?php
require_once('class.phpmailer.php');
$email1 = new PHPMailer();
$email1->CharSet = 'UTF-8';
$email1->IsHTML(true);
$email1->From = '[email protected]';
$email1->FromName = 'Имя проекта';
$email1->Subject = "Тема (Имя проекта): ".$form_name;
$email1->Body = $bodytext1;
$email1->AddAddress( '[email protected]' );
if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
$email1->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
}
?>
foreach ($_FILES['file'] as $file) {
if (isset($file) && $file['error'] == UPLOAD_ERR_OK) {
$email1->AddAttachment($file['tmp_name'], $file['name']);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question