PHPMailer POST https://mysite/includes/php/sendmale.php 500 (Internal Server Error)

в консоли ссылается на строку 18 в js файле, но в error log ошибка 500 на require никак не могу заставить phpmailer работать

это код из sendmale.php <?php

    echo "string";

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;

    echo "string2";

    require('/var/www/user85155/data/www/мойсайт/includes/PHPmailer/src/Exception.php');
    require('/var/www/user85155/data/www/мойсайт/includes/PHPmailer/src/SMTP.php');
    require('/var/www/user85155/data/www/мойсайт/includes/PHPmailer/src/PHPmailer.php');

    echo "string4";

    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;// debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "contactform@мойсайт.kg";
    $mail->Password = "qwerty0000";
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->setFrom('contactform@иойсайт.kg', 'мой сайт - Landing page');
    $mail->addAddress('info@мойсайт.kg');
    $mail->CharSet = 'UTF-8';
    $mail->setLanguage('ru', 'phpmailer/language/');
    $mail->IsHTML(true);

    echo "string3";
    // from who
    
    // to who
    
    // subject
    $mail->Subject = 'Заявка на сотрудничество!';

    // mail
    if (trim(!empty($_POST['name']))) {
        $body .= '<p><strong>Имя:</strong>' . $_POST['name'] . '</p>';
    };
    if (trim(!empty($_POST['email']))) {
        $body .= '<p><strong>E-mail:</strong>' . $_POST['name'] . '</p>';
    };
    if (trim(!empty($_POST['message']))) {
        $body .= '<p><strong>Сообщение:</strong>' . $_POST['message'] . '</p>';
    };

    // file
    if (!empty($_FILES['file']['tmp_name'])) {
        $filePath = __DIR__ . '/files/' . $_FILES['file']['name'];
        // upload
        if (copy($_FILES['file']['tmp_name'], $filePath)) {
            $fileAttach = $filePath;
            $body .= '<p><strong>Приложенные файлы</p></strong>';
            $mail->addAttachment($fileAttach);
        };
    };

    // send
    if (!$mail->send()) {
        $message = 'Ошибка';
    } else {
        $message = 'Отправлено';
    };

    $responce = ['message' => $message];

    header('Content-type: applications/json');
    echo json_encode($responce);

?>

это код из validmale.js

 "use strict"

document.addEventListener('DOMContentLoaded', function () {
    const form = document.getElementById('form');
    const mail = document.getElementById('mail');
    form.addEventListener('submit', formSend);

    async function formSend(e) {
        e.preventDefault();

        let error = formValidate(form);

        let formData = new FormData(form);
        formData.append('file', formFile.files[0]);

        if (error === 0) {
            mail.classList.add('_sending');
            let responce = await fetch('includes/php/sendmale.php', {
                method: 'POST',
                body: formData
            });

            if (responce.ok) {
                let result = await responce.json();
                alert(result.message);
                formFileName.innerHTML = '';
                form.reset();
                mail.classList.remove('_sending');
            } else {
                alert('Ошибка');
                mail.classList.remove('_sending');
            }
        } else {
            alert('Заполните обязательные поля');
            mail.classList.remove('_sending');
        }
    }

    function formValidate(form) {
        let error = 0;
        let formReq = document.querySelectorAll('._req');

        for (let index = 0; index < formReq.length; index++) {
            const input = formReq[index];
            formRemoveError(input);

            if (input.classList.contains('_email')) {
                if (emailTest(input)) {
                    formAddError(input);
                    error++;
                }
            } else {
                if (input.value == '') {
                        formAddError(input);
                        error++;
            }
            }
        }

        return error;
    }
    // add/remove error
    function formAddError(input) {
        input.classList.add('_error');
    }
    function formRemoveError(input) {
        input.classList.remove('_error');
    }
    // check email sintax
    function emailTest(input) {
        return !/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(input.value);
    }
    // get added file
    const formFile = document.getElementById('file');
    // show added file name
    const formFileName = document.getElementById('preview');

    // changes in the input file
    formFile.addEventListener('change', () => {
        uploadFile(formFile.files[0]);
        let file = formFile.files[0];

            formFileName.innerHTML = `Выбран: ${file.name}`; // например, my.png
    });

    function uploadFile(file) {
        if (file.size > 10 * 1024 * 1024) {
            alert('Файл должен быть меньше 10 МБ.');
            return;
        }

    }












})

я уже и не знаю где искать рабочую схему, помогите пожалуйста


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

Автор решения: Lion

в 18 строке у вас идет ссылка на файл

includes/php/sendmale.php

Скорее всего js не может его найти по этому относительному пути. Вам нужно попробовать указать абсолютный пусть.

→ Ссылка