This form handles the form data and a single image nicely.
However... when I add the brackets [] to the file input name to handle multiple images, I receive no images at all in the receiving email. I just receive a blank 'alternative' that displays "Array".
Please advise me what I am missing in this code.
HTML:
<!DOCTYPE html>
<head>
<title>My Form</title>
</head>
<form action="my.php" method="post" enctype="multipart/form-data">
<input type="text" id="userName" name="userName" placeholder=" Enter
Your Full Name"><br><br>
<input type="text" id="userEmail" name="userEmail" placeholder=" Enter
Your Emal Address"><br><br><br>
<input type="file" id="file" name="userImages" multiple /><br><br><br>
<input type="submit" id="submitButton" name="submitButton" value="Submit
Form">
</form>
</html>
PHP:
<?php
$filenameee = $_FILES['userImages']['name'];
$fileName = $_FILES['userImages']['tmp_name'];
$name = $_POST['userName'];
$email = $_POST['userEmail'];
$composition =
"\r\nName: ". $name .
"\r\nEmail Address: " . $email;
$subject ="Email Subject Line";
$fromname ="$name";
$fromemail = "$email";
$mailto = 'myaddress@email.com';
$content = file_get_contents($fileName);
$content = chunk_split(base64_encode($content));
$separator = md5(time());
$eol = "\r\n";
$headers = "From: ".$fromname." <".$fromemail.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $composition . $eol;
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filenameee . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
if (mail($mailto, $subject, $body, $headers)) {
echo "Thank you for submitting your form."; // The message the user will see after their form
has sent
} else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
}