I have a script that resizes up to 5 uploaded images. These are written into an array and I'd like to attach all of them to an email. I have the following script but it is only attaching 1 image, where do I need to loop to attach all of them?
$path = "./uploads/";
foreach ($filenameresized as $filename) {
$file = $path.$filename;
}
$content = file_get_contents( $file);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$subject = "ENQUIRY - Evolve My Boiler (" . $name . " - " . $date . ")" ;
$from_name = "Evolve Maintenance Ltd";
//$from_mail = "info@evolvemaintenance.co.uk, mail@helenlee.co.uk";
$from_mail = "mail@helenlee.co.uk";
$replyto = "";
$cc = "";
$bcc = "";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; // generate a random string to be used as the boundary marker
$file_count = count($filenameresized); //count total files attached
$boundary = md5("specialToken$4332"); // boundary token to be used
// header
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
// message body
$message = "<b>Hello</b>";
// message & attachment
$nmessage = "--".$uid."\r\n";
$nmessage .= "Content-Type: text/html;charset=utf-8\n";
$nmessage .= "Content-Transfer-Encoding: 7bit\n\n";
$nmessage .= $message."\r\n\r\n";
$nmessage .= "--".$uid."\r\n";
$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$nmessage .= "Content-Transfer-Encoding: base64\r\n";
$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$nmessage .= $content."\r\n\r\n";
$nmessage .= "--".$uid."--";
if (mail($from_mail, $subject, $nmessage, $header)) {
return true; // Or do something here
} else {
echo 'Oops something went wrong - please <a href="find-your-boiler.php">try again</a>';
}