I am patching together a script to attach one or more files to an email. Which files get attached depends on a form with checkboxes.
I've got an array with the filenames (based upon the form values):
// see which boxes are checked
foreach($_POST['check'] as $value) {
$files = array($value);
}
...but I need to get the array to look like this for the script I'm using:
// array with filenames to be sent as attachment
$files = array("file_1.ext","file_2.ext","file_3.ext",......);
$just=count($files);
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],'rb');
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= “Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
if($x==($just-1))
{
$message .= "–{$mime_boundary}-\n";
} else
{
$message .= "–{$mime_boundary}\n";
}
}
Unless of course there is another way to use the array w/o quotes/commas.
Thanks...