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" />
   </form>

    <?php

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

        if(isset($_POST["contact"]))
        {

            
            $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_r($_FILES);

            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];

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

		try{
			$mail->isSMTP();
			//$mail->SMTPDebug = 1;
			$mail->Host = 'smtp.gmail.com';
			$mail->SMTPAuth = true;
			$mail->Username = 'xxx@gmail.com';
			$mail->Password = 'xxxxxxx;';
			$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
			$mail->Port = 587;
			$mail->setFrom('xxx@gmail.com');
            $mail->Subject = $subj;
            $mail->Body    = $new_body;
            $mail->AddAttachment($uploadfile);
            $mail->AltBody = 'uploads/';
           	$mail->addAddress($_POST['email']);
             if(!$mail->Send())
                {
                echo "Mailer Error: " . $mail->ErrorInfo;
                }
                else
                {
                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…

2 Likes

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