0

I am designing a form for an e-commerce website using Prestashop 1.6, in this form I would like to allow customers to send multiple pictures.

For example : a customer wants to send back his order because he received the wrong product, but the customer service will need pictures of the packaging and proof that there is an issue, so he will need to upload his picture, then when the customer click on submit, I would like to send it in a email as attachment.

How can I proceed ?

<div class="box-container-1">
 <img src="http://dev.piscine-clic.com/img/icone-etat.svg" alt="photos">
  <label for="file">Envoyez nous des photos du matériel ainsi que de son emballage que
  vous souhaitez retourner</label>
<!-- INPUT pour envoyer les photos et preuves de retour -->
  <input class="file-button" type="file" id="file" name="file" multiple />
</div>

Thanks all for your future responses.

  • 1
    Does this answer your question? [How can I select and upload multiple files with HTML and PHP, using HTTP POST?](https://stackoverflow.com/questions/1175347/how-can-i-select-and-upload-multiple-files-with-html-and-php-using-http-post) – herau Jan 11 '21 at 14:55
  • Thank you for this reponse, I've already checked this, but my issue is to send attachment in an email and no upload it on a server. – MatthieuIX Jan 11 '21 at 15:22

1 Answers1

0

Your file input looks correct. On the server side, I would recommend using a class like PHPMailer, and then processing the form submit like so:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $mail = new PHPMailer(true);
         
    try {
        $mail->isSMTP();
        $mail->Host = 'host';
        $mail->Username = 'username';
        $mail->Password = 'password';
        
        $mail->setFrom($from);
        $mail->addAddress($to);
        $mail->Subject = $subject;
        $mail->Body = $body;
        
        $file_count = count($_FILES['file']['name']);
        
        if ($file_count) {

            for($i=0 ; $i < $file_count ; $i++) {
                if (file_exists($_FILES['file']['tmp_name'][$i]) && is_uploaded_file($_FILES['file']['tmp_name'][$i])) {
                    
                    $file_path = $_FILES['file']['tmp_name'][$i];
                    $file_name = pathinfo($_FILES['file']['name'][$i], PATHINFO_FILENAME);
                    $file_ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION));
                    
                    $mail->addAttachment($file_path, $file_name . '.' . $file_ext);
                }
            }
        }

        $mail->send();

    } catch (Exception $e) {
        echo $mail->ErrorInfo;
        exit;
    }
}
user1392897
  • 831
  • 2
  • 9
  • 25