Can somebody please have a look at my code below and let me know where I am going wrong. I am trying to send out mulile attachments. At the moment an email is being sent to the requested recipients but the attachments are not arriving and the email comes from 'httpd'. Am I using arrays correctly for file uploads?
Any pointers would be greatly appreciated
Thanks
//page1.html
<form action="page1.html" method="post">
<tr>
<td align="left" class="formlabel">Select Number Of Attachments:</td>
<td class="formtext"> <select name="noofuploads">
</select> </td>
</tr>
<tr>
<td colspan=2 class="formtext"> <input type="button" name="uploads" value="GO"></td>
</select> </td>
</tr>
</form>
<form action="page2.html" method="post" enctype="multipart/form-data">
<tr>
<td align="left" class="formlabel">Subject:</td>
<td class="formtext"> <input type="text" size"10" name="subject"></td>
</tr>
<tr>
<td align="left" valign="top" class="formlabel">Message Body:</td>
<td valign="top" class="formtext"> <textarea name="message" cols="50" rows="10" wrap="virtual</textarea></td>
</tr>
//while loop which echos the Add Attachments File Browse depending on the number chosen in the select box 'noofuploads'
<tr>
<td align="left" class="formlabel">Add Attachments: </td>
<td class="formtext"> <input type="file" size"10" name="attachment"></td>
</tr>
//page2.html
$nooffiles = $_POST['noofuploads'];
function attachfiles($text, $from, $file, $type, $name) {
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$header = "From: $from\nReply-To: ".$from."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=".$uid."\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= $text."\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: ".$type."; name=\"".$name."\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$name."\"\n\n";
$header .= $content."\n";
$header .= "--".$uid."--";
}
$consultant = mysql_query("SELECT * FROM consultants WHERE consultantID='".$_SESSION['consultantID']."'", $link_id) or die(mysql_error());
$query_data = mysql_fetch_array($consultant);
//scroll through list of attachments
for($i=0;$i<$nooffiles;$i++){
$filename[$i] = $FILES['attachments']['name'][$i];
$$filename_name[$i] = $FILES['attachments']['tmp_name'][$i];
$filename_type[$i] = $_FILES['attachments']['type'][$i];
attachfiles($_POST['message'], $query_data['firstname']." ".$query_data['surname'], $filename, $filename_type, $filename_name);
}
//scroll through recipients
foreach($POST["email"] As $val){
$candidates = mysql_query("SELECT email FROM personal WHERE candidateID='$val'", $link_id) or die(mysql_error());
$query_data = mysql_fetch_array($candidates);
mail($query_data['email'],$POST['subject'],$_POST['message'],$header);
}