Answer the question
In order to leave comments, you need to log in
How to attach multiple files to an email using PHPmailer?
There is a code that can send only one picture. I duplicate functions, still only one picture comes.
Working code:
<input type="file" name="myfile[]" multiple id="myfile">
$file = $_FILES['myfile'];
if (!empty($file['name'][0])) {
for ($ct = 0; $ct < count($file['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($file['name'][$ct]));
$filename = $file['name'][$ct];
if (move_uploaded_file($file['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
$rfile[] = "Файл $filename прикреплён";
} else {
$rfile[] = "Не удалось прикрепить файл $filename";
}
}
}
$file = $_FILES['myfile'];
if (!empty($file2['name'][0])) {
for ($ct = 0; $ct < count($file['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($file2['name'][$ct]));
$filename = $file2['name'][$ct];
if (move_uploaded_file($file2['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
$rfile[] = "Файл $filename прикреплён";
} else {
$rfile[] = "Не удалось прикрепить файл $filename";
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question