0

I'm attempting to send multiple files to my email but not are attaching properly. This is what I'm receiving:

enter image description here

Here is what my form looks like:

<form action="FILE-SENDING.php" enctype="multipart/form-data" method="POST">
    <input type="text" name="name" placeholder="Name">
    <input type="text" name="contact" placeholder="Contact">

    <p>File 1:</p>
    <input type="file" name="file1">

    <p>File 2:</p>
    <input type="file" name="file2">

    <p>File 3:</p>
    <input type="file" name="file3">

    <button type="submit" value="Send File">Submit</button>
</form> 

And my PHP:

<?php
$name = $_POST['name'];
$contact= $_POST['contact'];

$file1= $_FILES['file1'];
$file2= $_FILES['file2'];
$file3= $_FILES['file3'];

$to = "my@email.com";
$subject = "New Form Received!";

$txt =
"Name = ". $name . 
"\r\n Contact = " . $contact . 
"\r\n File 1 = " . $file1  .
"\r\n File 2 = " . $file2 .
"\r\n File 3 = " . $file3 ;

$headers = "From: noreply@email.com" . "\r\n" .
"CC: private-sender@gmail.com";

if($contact!=NULL){
    mail($to,$subject,$txt,$headers);
}

header("Location:Success.html");
?>

I attempted different ways to integrate "$_FILES" but none landed a hit. Suspecting something may be missing on HTML, but not sure what.

droopsnoot
  • 931
  • 1
  • 7
  • 11
  • `$_FILES` is a 2-dimensional associative array. It doesn't contain the uploaded data, that's in the file named in `$_FILES['file#']['tmp_name']` – Barmar Jul 08 '23 at 16:24
  • You should read a tutorial on how PHP processes uploaded files. – Barmar Jul 08 '23 at 16:25
  • Look at this answer in the suggested duplicate - https://stackoverflow.com/a/12313090/7867822 – Anurag Srivastava Jul 08 '23 at 17:03
  • Even if you fixed the use of `$_FILE`, you can't attach a file to an email just by mentioning its name; you have to format the email in s special way that includes the full days of each file. I strongly recommend you don't spend time manually implementing that format, but instead find a PHP library that will do it all for you - PHPMailer, Symfony Mailer, etc – IMSoP Jul 09 '23 at 09:21

0 Answers0