How to send multiple attachment in single mail in php
Following the reusability principles, you can use https://github.com/PHPMailer/PHPMailer
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Source: How to attach two or multiple files and send mail in PHP
How to Add Multiple Attachments to an Email Using PHPMailer
This question was answered by synchro on another thread. https://github.com/PHPMailer/PHPMailer/issues/2098
"The threads you pointed at are years old!
The article about unique IDs is long obsolete; inline attachments with duplicate cid values will still be ignored, but that's expected behavior, and only applies to inline attachments created using addEmbeddedImage() and addStringEmbeddedImage().
The key problem here is that you're just not handling uploads properly. How you should handle uploads is covered in the PHP docs, and all that occurs before PHPMailer has any involvement.
First of all, you need to understand how file inputs work. These determine what shows up in the $_FILES superglobal that PHP populates for you. You can either have multiple file-type inputs that select a single file each, or you can have a single one that allows you to select multiple files. PHPMailer doesn't care either way, but you have to.
Next, you need to make sure you use move_uploaded_file or at least is_uploaded_file in order to validate what's in the $_FILES superglobal, otherwise, it's not safe.
Thirdly, you need to check whether the calls to addAttachment() are successful – at present, you're just assuming they work and have no error checking at all.
So, I recommend you take a look at the single and multiple file upload examples, both of which do all of the above, and there are no known problems with adding multiple attachments."
multiple attachments going with single mail from phpmailer
$mail = new PHPMailer; // this should be inside of while, I think...
Related Topics
PHP How to Get the Base Domain/Url
How to Use Two Submit Buttons, and Differentiate Between Which One Was Used to Submit the Form
Get Date for Monday and Friday for the Current Week (Php)
Simple Comet Example Using PHP and Jquery
How to Use PHP in a JavaScript Function
Using Laravel Socialite to Login to Facebook
Select Within 20 Kilometers Based on Latitude/Longitude
Inserting Now() into Database with Codeigniter's Active Record
PHP Datetime Microseconds Always Returns 0
How to Install an Older Version of PHPunit Through Pear
How to Access a Different Controller from Inside a Controller Symfony2
Require_Once () or Die() Not Working
How to Reuse Deleted Primary Keys in MySQL
Using SQLite3 in PHP How to Count the Number of Rows in a Result Set
Make a Https Request Through PHP and Get Response
How to Post Button Value to PHP
What Is a Good Method to Sanitize the Whole $_Post Array in PHP