Why not come files from the input file?

mail.php
<?php
// Who sent
$to = 'test@yandex.ru';

// The subject of the email
$subject = 'Request from website';

 $headers = "From:" . strip_tags($sendfrom) . "\r\n";
 $headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";
 $headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
// The message itself
$message = '
<!DOCTYPE html>
<html lang="EN">
the <head>

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Subject page</title>
</head>
the <body>
<table cellpadding="0" cellspacing="0" style="width:600px; max-width:600px; margin: 0px auto; border:1px solid #ddd;">
<thead>
the <tr>
 <td style="text-align:center; padding:16px; color:#fff; font-size:18px;background:#FEA707;" colspan="2">'.$_POST["form"].'</td>
</tr>
</thead>
the <tr>
 <td style="width:35%; border:1px solid #ddd; padding:12px 20px; font-size:16px;">customer Name:</td>
 <td style="width:65%; border:1px solid #ddd; padding:12px 20px; text-align:center; font-size:16px;">'.$_POST["name"].'</td>
</tr>
the <tr>
 <td style="width:35%; border:1px solid #ddd; padding:12px 20px; font-size:16px;">Phone:</td>
 <td style="width:65%; border:1px solid #ddd; padding:12px 20px; text-align:center; font-size:16px;">'.$_POST["phone"].'</td>
</tr>
the <tr>
 <td style="width:35%; border:1px solid #ddd; padding:12px 20px; font-size:16px;">E-mail:</td>
 <td style="width:65%; border:1px solid #ddd; padding:12px 20px; text-align:center; font-size:16px;">'.$_POST["email"].'</td>
</tr>
the <tr>
 <td colspan="2" style="border:1px solid #ddd; background:#eee; padding:12px 20px; font-size:14px; text-align:center;" >This message sent successfully</td>
</tr>
</table>
</body>
</html>
';

// Download only the core WordPress
define( 'WP_USE_THEMES', false );
require( '../../../../wp-load.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );

$attachment = wp_handle_upload($_FILES['fileFF'], array('test_form' => FALSE));
if ($attachment) {
// Send the email
// print_r($attachment);
// exit();
// /Send letter
$sent_message = wp_mail( $to, $subject, $message, $headers, $attachment ['file'], $attachment["url"] );

if ( $sent_message ) {
 // If the message was successfully sent
 header('Location:/? thanks status=success');
 // print_r($_FILES);
} else {
 // Error when sending
 header('Location:/? thanks status=error');
}
}
else {
 header('Location:/? thanks status=error');
 exit(); 
}


form which come from attachments
<form enctype="multipart/form-data" action="<? echo get_template_directory_uri().'/mail/mail.php'; ?>" method="POST" class="main-form">
 <input type="hidden" name="form" value="Form on the main page">
 <div class="form-row frst main-form__row">
 <div class="form-input main-form__input">
 <input name="name" required placeholder="Your name" type="text">
 <span class="form-input__line"></span>
</div>

 <div class="form-input main-form__input">
 <input name="phone" required placeholder="Your telephone" type="tel">
 <span class="form-input__line"></span>
</div>

 <div class="form-input main-form__input">
 <input name="email" placeholder="Your email" type="email">
 <span class="form-input__line"></span>
</div>



</div>
 <div class="form-row main-form__row">
 <input name="fileFF" type="file" id="updateFile">
 <label class="main-form__block" for="updateFile">
 <i class="fa fas-download"></i>
 <p class="main-form__label">Attach technical specification</p>
</label>
 <button class="button main-form__btn" type="submit">Send</button>
</div>
 </form>


Form of which does not come attachments
<form action="<? echo get_template_directory_uri().'/mail/mail.php'; ?>" method="POST" class="contacts-form">
 <input type="hidden" name="form" value="Block 'contact'">
 <div class="form-input contacts-input">
 <input name="name" id="message contact_name" required type="text">
 <label for="message contact_name">Your name</label>
 <span class="form-input__line"></span>
</div>

 <div class="form-input contacts-input">
 <input name="phone" id="contact_tel" required type="tel">
 <label for="contact_tel">Your phone</label>
 <span class="form-input__line"></span>
</div>


 <div class="form-input contacts-input">
 <input name="email" id="contact_email" type="email">
 <label for="contact_email">Your email</label>
 <span class="form-input__line"></span>
</div>


 <div class="form-row contacts-file">
 <input name="fileFF" type="file" id="updateFileCont">
 <label class="main-form__block" for="updateFileCont">
 <i class="fa fas-download"></i>
 <p class="main-form__label">Attach technical specification</p>
</label>
</div>
 <button href="#" data-click="nextSlide" class="section-btn">
 <span class="section-btn__circle">
 <img src="<? echo get_template_directory_uri(); ?>/assets/img/long-arrow.png" alt="Arrow">
</span>
</button>
 </form>


Hello, top handler, working contact form not working form.
Don't know why from 1 form come the attachments from the input file and the other not?
April 4th 20 at 00:44
1 answer
April 4th 20 at 00:46
Solution
enctype="multipart/form-data" required for forms with file
https://i.imgur.com/F0qGflZ.png It is here to place you need? Unfortunately did not help( - Antonetta5 commented on April 4th 20 at 00:49
No. Here <form enctype="multipart/form-data" action=" - camron commented on April 4th 20 at 00:52
@camron, you're right, thank you very much)) - Antonetta5 commented on April 4th 20 at 00:55

Find more questions by tags PHPWordPress