Hi Folks
I need some guidance in trying to write something that dynamically sends email to users with a number of attachments. I've never used attachments before with PHP and can't find what i'm looking for in any of yhe forums. Below is some snippets of code/and pseudo
Basically i've got a page1 which will allow the user to choose how many files they wish to attach to the email along with entering the subject, message etc.......If the user selects a number of files to upload then the page will recall itself and dynamically put the correct number of File Browser input types on the form.
Once the form is filled in I want to attach the number of files uploaded to an email and sent the email out
//snippet from page 1.html
<form action="$PHP_SELF" 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>
//end while
</form>
//snippet from page 2.html
$subject //from querystring
$message //from querystring
$noofuploads //from querystring
for($i=0;$i<noofuploads($FILES["fileup"]["tmp_name"]);$i++){
$name = $FILES['fileup']['name'][$i];
$temp = $FILES['fileup']['temp'][$i];
$size = $FILES['fileup']['size'][$i];
$type = $FILES['fileup']['type'][$i];
if($size > 0){
$new_name = time(). "" . $name;
$new_name = str_replace" ","_",$new_name);
@move_upload_file($temp, $up_dir . $new_name);
$all_names .= $new_name\n";
}
}
$from = "me@hotmail.com";
$to = "you@hotmail.com";
//This is where i'm stuck. What do I need to do to set up the headers for mime types and attach the number of files to a mail message to be sent out? Essentially I want to loop around depending on the number of attachments and then push these attachments out to the user? Also are these temporary files automatically removed from the directory or do I need to remove them myself so that they do not build up?
Hope somebody can guide me. Thanks