Форма отлично отправляется, но никак не получается прикрепить туда файл, подскажите, в чем может быть проблема HTML: <formid="form"action="send.php"enctype="multipart/form-data"class="footer__content"id="form1"> <h2class="footer__title">Обратная связь</h2> <divclass="footer__subtitle"> Заполните обязательные поля и мы начнем готовить ваш проект немедленно </div> <ulclass="footer__list-input"> <liclass="footer__item-input"> <divclass="footer__wrapper-input"> <labelfor=""class="input js-input"> <inputname="userName"class="input__input"requiredtype="text"> <divclass="input__placeholder"> Имя </div> </label> </div> </li> <liclass="footer__item-input"> <divclass="footer__wrapper-input"> <labelfor=""class="input js-input"> <inputname="userPhone"class="input__input js-phone-mask"requiredtype="tel"> <divclass="input__placeholder"> Телефон </div> </label> </div> </li> <liclass="footer__item-input"> <divclass="footer__wrapper-input"> <labelfor=""class="input js-input"> <inputname="userEmail"class="input__input"requiredtype="email"> <divclass="input__placeholder"> Email </div> </label> </div> </li> <liclass="footer__item-input"> <divclass="footer__wrapper-input"> <labelfor=""class="input js-input"> <inputname="userWords"class="input__input"type="text"> <divclass="input__placeholder"> Комментарий к сообщению </div> </label> </div> </li> </ul> <labelclass="add-file js-file"> <inputname="upload"id="upload"type="file"class="add-file__input"> <spanclass="add-file__desc">Добавить файл</span> <svgclass="icon icon-plus add-file__icon"> <usexlink:href="#plus"></use> </svg> </label> <buttontype="submit"class="btn footer__btn"> <spanclass="btn__text"> Отправить </span> </button> </form> PHP: <?php $userName = $_POST['userName']; // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; // Load Composer's autoloader require 'phpMailer/PHPMailer.php'; require 'phpMailer/SMTP.php'; require 'phpMailer/Exception.php'; $title = "Заголовок письма"; $body = " <h2>Новое письмо</h2> <b>Имя:</b> $name<br> <b>Почта:</b> $email<br><br> <b>Сообщение:</b><br>$text "; // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(); try { //Server settings $mail->SMTPDebug = 0; // Enable verbose debug output $mail->isSMTP(); $mail->CharSet = "UTF-8"; // Send using SMTP $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'goncharovnikita713@gmail.com'; // SMTP username $mail->Password = '***********'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above //Recipients $mail->setFrom('goncharovnikita713@gmail.com', 'Никита'); $mail->addAddress('HUJIbCOH@yandex.ru', 'Joe User'); // Add a recipient // Content $mail->addAttachment($_FILES['upload']['tmp_name'], $_FILES['upload']['name']); $mail->isHTML(true); // Set email format to HTML $mail->Subject = "Тема письма с файлом"; $mail->Body = "Имя пользователя: ". $userName.; $mail->send(); echo 'Отправлено'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }
Прежде чем пытаться отправлять файл - его все же нужно загрузить почитайте про функцию PHP: move_uploaded_file() для чего она используется, ну и используйте ее по назначению