Как отправить прикрепленный файла в форме - Wordpress

Помогите разобраться. Я пытаюсь отправить письмо на почту с прикрепленным файлом от пользователя. Собственно функция для отправки:

function stex_send_mail () {

    $method = $_SERVER['REQUEST_METHOD'];

    if ($method !== 'POST') {
      exit();
    }

    $admin_email = '[email protected]';
    $form_subject = '`STEX` CV';
    $message = '';
    
    if ( !function_exists( 'wp_handle_upload' )) {
            require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploadedfile       = $_FILES['uploaded_file'];
    $upload_overrides   = array( 'test_form' => false );
    $movefile           = wp_handle_upload( $uploadedfile, $upload_overrides );


        $attachments = $movefile[ 'file' ];
        

    $color_counter = 1;

    foreach ($_POST as $key => $value) {
      if ($value === '') {
        continue;
      }
      $color = $color_counter % 2 === 0 ? '#fff' : '#f8f8f8';
      $message .= "
        <tr style='background-color: $color;'>
          <td style='padding: 10px; border: 1px solid #e9e9e9;'>$key</td>
          <td style='padding: 10px; border: 1px solid #e9e9e9;'>$value</td>
        </tr>";

      $color_counter++;
    } 

    function adopt($text) {
      return '=?utf-8?B?'.base64_encode($text).'?=';
    }

    $message = "<table style='width: 100%;'>$message</table>";

    $headers = "MIME-Version: 1.0" . PHP_EOL .
        "Content-Type: text/html; charset=utf-8" . PHP_EOL .
        'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
        'Reply-To: '.$admin_email.'' . PHP_EOL;

    
    $success_send = wp_mail($admin_email, adopt($form_subject), $message, $headers, $attachments);

    if ($success_send) {
      echo 'success';
    } else {
      echo 'error';
    }
        
    wp_die();
}

Я так понимаю чтоб отправить файл, его нужно сначала загрузить на сервер, а потом послать. Но в письме приходит просто путь к файлу. Я так понимаю что проблема в файле JS

;(function() {
  var forms = document.querySelectorAll('.form-send');

  if (forms.length === 0) {
    return;
  }

  var serialize = function(form) {
    var items = form.querySelectorAll('input, select');
    var str = '';
    for (var i = 0; i < items.length; i += 1) {
      var item = items[i];
      var name = item.name;
      var value = item.value;
      var separator = i === 0 ? '' : '&';

      if (value) {
        str += separator + name + '=' + value;
      }
    }
    return str;
  };

  var formSend = function(form) {
    var data = serialize(form);
    var xhr = new XMLHttpRequest();
    var url = 'mail/mail.php';
    
    xhr.open('POST', url);
    xhr.setRequestHeader('Content-Type', 'multipart/form-data');

    xhr.onload = function() {
      var activePopup = document.querySelector('.popup.is-active');

      if (activePopup) {
        activePopup.classList.remove('is-active');
      } else {
        myLib.toggleScroll();
      }

      if (xhr.response === 'success') {
        document.querySelector('.popup-thanks').classList.add('is-active');
      } else {
        document.querySelector('.popup-error').classList.add('is-active');
      }

      form.reset();
    };

    xhr.send(data);
  };

  for (var i = 0; i < forms.length; i += 1) {
    forms[i].addEventListener('submit', function(e) {
      e.preventDefault();
      var form = e.currentTarget;
      formSend(form);
    });
  }
})();

Ответы (0 шт):