How to Attach multiple file/images and can also reply in email

<form method="post" action="" enctype="multipart/form-data">

                    <input type="text" name="name" placeholder="Your Name *">
                    <input type="email" name="email" placeholder="Email *">
                    <textarea name="msg" placeholder="Your Message"></textarea>

                    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
                    <input type="file" name="userfile"  />

                <input name="contact" type="submit" value="Submit Enquiry" />


	require 'PHPMailer-master/src/Exception.php';
	require 'PHPMailer-master/src/PHPMailer.php';
	require 'PHPMailer-master/src/SMTP.php';
   	use PHPMailer\PHPMailer\PHPMailer;
	use PHPMailer\PHPMailer\Exception;


            $uploaddir = 'uploads/';
            $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
            //echo '<pre>';
            if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
                echo "File is valid, and was successfully uploaded.\n";
            } else {
                echo "Possible invalid file upload !\n";
            echo 'Here is some more debugging info:';

            print "</pre>";
            $mail_body = array($_POST['name'], $_POST['email'] , $_POST['msg']);
            $new_body = "Name: " . $mail_body[0] . ", Email " . $mail_body[1] . " Description: " . $mail_body[2];

            $subj = 'New enquiry '. date("Y-m-d h:i:sa", $d);
            $mail = new PHPMailer(true);

			//$mail->SMTPDebug = 1;
			$mail->Host = '';
			$mail->SMTPAuth = true;
			$mail->Username = '';
			$mail->Password = 'xxxxxxx;';
			$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
			$mail->Port = 587;
            $mail->Subject = $subj;
            $mail->Body    = $new_body;
            $mail->AltBody = 'uploads/';
                echo "Mailer Error: " . $mail->ErrorInfo;
                echo '<p>       Success              </p> ';
        }catch(Exception $e){
			echo $e->getMessage();


I have this code for email and using PHPMailer my email can only attach a single file/image and can also send but I want to do is can attach multiple file/image and can also reply .

Have you tried adding a second AddAttachment for the additional attachment?

To set the reply to address you need to set setFrom.

Not yet .

Not trying to offend anyone, but why do some beginners completely ignore Google?

Get me right, It’s not difficult to answer even such basic questions, but you would save so many time of waiting for replies if you simply type “phpmailer multiple attachments” in Google and follow the first result…


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.