I would like to know about attaching multiple attachment in single mail and send . Please refer my following oode. In this only one file is getting attached. That is second file. First file is not at all considering for attaching. But file is being created properly in the path specified.
$filename=array($filenamee1 ,$filenamee2);
for($x=0;$x<count($filename);$x++){
echo $path.$filename[$x];
$file = $path.$filename[$x];
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "cc: ".$mailtoCC."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename[$x]."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename[$x]."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
}
if (mail($mailto, $subject, "", $header)) {
echo "<br>mail sent Successfully... OK";
} else {
echo "<br>mail send ... ERROR!";
}
Following the reusability principles, you can use https://github.com/PHPMailer/PHPMailer
Source: How to attach two or multiple files and send mail in PHP
This is what I came up with for multiple files with form file name userfile:
For those who want to send multiple files using phpMailer and input file multiple. I joined and used the above two codes of @Rishi and @Matheno to achieve this result that dinamically add attachments selecteds by user.
On your input file name remember to put brackets:
On your php send file:
Instead of:
Use: