Actually there is a site on MODX revo. There is a form with which the user can send in addition to his data also a file. Ie something like

<script> $("#main-pofo").submit(function() { var th = $(this); $.ajax({ type: "POST", url: "/assets/php/phone.php", data: th.serialize() }).done(function() { $(th).find(".success").addClass("active").fadeIn(); setTimeout(function() { $(th).find(".success").removeClass("active").fadeOut(); th.trigger("reset"); }, 1000); }); return false; }); </script> 
 <form id="main-pofo" method="post"> <input type="text" name="name"> <input type="file" name="file"> </form> //собственно сам файл phone.php <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'src/Exception.php'; require 'src/PHPMailer.php'; require 'src/SMTP.php'; $name = $_POST['user_name']; $email = $_POST['user_mail']; $message = $_POST['user_msg']; $phone = $_POST['user_phone']; $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = '********'; $mail->SMTPAuth = true; $mail->Username = '********'; $mail->Password = '*******'; $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->CharSet = 'utf-8'; //Recipients $mail->setFrom(********); $mail->addAddress(*******); //$mail->addAddress('ellen@example.com'); //$mail->addReplyTo('info@example.com', 'Information'); //$mail->addCC('cc@example.com'); //$mail->addBCC('bcc@example.com'); // Attachments //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name $mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']); // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'С сайта ******'; $mail->Body = "<br><b>ФИО или организация:</b>$name<br><b>Email:</b>$email<br><b>Телефон:</b>$phone <br><b>Сообщение:</b>$message"; $mail->AltBody = 'Что-то пошло не так и поэтому здесь этот текст'; ?> 

An example form is simple. The file is not transferred. What to do and how to fix it?

  • Your problem is that the file is not transferred along with the other form parameters in the ajax request? Can you reformulate your question, since the problem is not directly related to php / modX / phpMail? Then more participants can help you with advice. - Jigius
  • Yes, thank you, you are right the file is simply not transmitted. Added var formData =$(".popup-form").submit(function(e){ return ; }); var formData = new FormData(formData[0]); var formData =$(".popup-form").submit(function(e){ return ; }); var formData = new FormData(formData[0]); And put the data: formData. So the issue is resolved. - Pavel A.A.

0