I need to add in a contact form a section for people to upload their information (in PDF or image (JPG/PNG/ETC)). I got the section to upload the file, but it isn't sending the PDF with the e-mail (e-mail is working fine, but it arrives without the file uploaded, i don't know why). i will put my HTML/PHP code, so if you could help me it to know where is the problem or how can i achieve to upload a file, it would be great!
HTML
<form class="mb-2" action="freetest.php" onsubmit="return validateForm();" method="post">
<div class="form-group">
<div>
<label class="mb-0">Name</label>
</div>
<div class="form-group">
<input class="form-control-input" type="text" id="firstName" name="firstName" placeholder="Your Name" required>
</div>
</div>
<div class="form-group">
<div>
<label class="mb-0">Last Name</label>
</div>
<div class="form-group">
<input class="form-control-input" type="text" id="lastName" name="lastName" placeholder="Amelie" required>
</div>
</div>
<div class="form-group">
<div>
<label class="mb-0">Mail</label>
</div>
<div>
<input class="form-control-input" type="text" name="email" id="yourEmail" placeholder="[email protected]" required>
</div>
</div>
<div class=form-group>
<label class="mb-0">?Any Question?</label>
<textarea class="form-control-textarea" rows="8" name="message" required></textarea>
</div>
<div class="form-group">
<div>
<label for="file-upload" class="custom-file-upload mt-2"><i class="fas fa-cloud-upload-alt"></i> Upload File</label>
<input id="file-upload" type="file" name="file" multiple="multiple" required>
</div>
</div>
<button type="submit" class="btn-solid-lg">Send</button>
</form>
PHP
<?php
$ToEmail = '[email protected]';
$EmailSubject = 'Free test';
$mailheader = "From: ".$_POST["lastName"]."
";
$mailheader .= "Reply-To: ".$_POST["email"]."
";
$mailheader .= "Content-type: text/html; charset=iso-8859-1
";
$MESSAGE_BODY = "First Name: ".$_POST["firstName"]."<br/>";
$MESSAGE_BODY .= "Last Name: ".$_POST["lastName"]."<br/>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br/>";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
question from:
https://stackoverflow.com/questions/65660810/php-upload-file-to-a-contact-form-and-email-it 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…