На почту не приходят все файлы

Вот php

$headers[] = 'Content-type: text/html; charset=utf-8';
    $fromMail = get_field('email_from_send','options');
    $mailTo = [];
    if( have_rows('emails_to_send','options') ):
        while ( have_rows('emails_to_send','options') ) : the_row();
            array_push($mailTo, get_sub_field('email_to_send','options'));
        endwhile;
    else :
        return;
    endif;

    define('MB', 1048576);
    $attachments = array();
    $fileTypesSub = array();
    if( have_rows('attachment_file_types','options') ):
        while ( have_rows('attachment_file_types','options') ) : the_row();
            array_push($fileTypesSub, get_sub_field('attachment_file_type','options'));
        endwhile;
    else :
        return;
    endif;
    if(!file_exists(__DIR__.'/uploaded/')) {
        mkdir(__DIR__.'/uploaded/', 0777, true);
    }
    if(isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name']) && $_FILES['file']['size']<=(10*MB)) {
        $upload = array(
            'name' => $_FILES['file']['name'],
            'tmp_name' => $_FILES['file']['tmp_name'],
            'extension' => pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION),
        );
        if(in_array(mb_strtolower($upload['extension'], 'UTF-8'), $fileTypesSub ) ) {
            $file = __DIR__.'/uploaded/'.basename($upload['name']);
            if(is_file($file)) {
                if(@unlink($file)){
                    if(@move_uploaded_file($upload['tmp_name'], $file)) {
                        chmod($file, 0777);
                        $attachments[] = $file;
                    }  
                }
            } else {
                if(@move_uploaded_file($upload['tmp_name'], $file)) {  
                    chmod($file, 0777);
                    $attachments[] = $file;
                }
            }  
        }
    }
    
    wp_mail($mailTo, $thm, $msg, $headers, $attachments);

    $emailSuccesMessage = get_field('message_successfully','options');
    echo $emailSuccesMessage;

Вот html

                <div class="dropdown_files">
                    <label for="customAttach"></label>
                    <input type="file" name="file" id="customAttach" multiple>
                </div>

Вот JS

$("#submitOrder").on("click", function (event) {
 event.preventDefault();
this_form = $(this).closest("form");
    if(this_form.find('input[type="file"][name="file"]').length>0 && window.FileReader) {
      var $file = this_form.find('input[type="file"][name="file"]');
      var files = $file[0].files;
      if(files.length>0) {
        var file = {};
        file['extension'] = files[0].name.split('.').pop();
        file['size'] = parseFloat(parseFloat(files[0].size/1024/1024).toFixed(2));
                var fileTypesStr = $("#fileTypes").text();
                var extensions = fileTypesStr.split(',');
        if(!extensions.includes(file['extension'].toLowerCase())) {                    
          alert('You are trying to upload a file with an invalid extension. Valid values: ' + extensions);
          error = 1;
        }
        if(file['size']>10) {
          alert('You are trying to upload a file larger than 10 MB. Please upload a smaller file.');
          error = 1;
        }
      }
    }
    if(typeof(this_form.find('input[type="file"][name="file"]')[0].files[0])!=='undefined') {
        formData.append('file', this_form.find('input[type="file"][name="file"]')[0].files[0]);
    }
    $.ajax({
        url: "/wp-admin/admin-ajax.php",
        method: 'post',
        processData: false,
        contentType: false,
        data: formData,
        success: function (response) {
            jQuery(this_form)[0].reset();
            this_form.find('input, textarea, select').removeClass('error');
            parentBlock = this_form.closest(".popup_content");
            parentBlock.find(".popup_form").addClass("hide");
            parentBlock.find(".succes_wrapp").fadeIn(200);
            $("#succesMessageOrder").html(response);
        },
        error: function(){
            alert('Ошибка при отправке');
        }
    });

Код написан в wordpres c использованием ACF. Файлы отправляются, но не все файлы приходят а только один. Хотя там стоит возможность множественного выбора. Нужно что бы приходили на почту все файлы. Что там не так?


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