mem0ri Posted December 22, 2006 Share Posted December 22, 2006 I have a mass e-mailer for a private members-only website worked out and functioning perfectly...(I'll post some of the code below)...the difficulty is that I want to be able to allow MULTIPLE attachments to the e-mail, not just one......when I simply add a 2nd file upload box and duplicate the multipart mime format with an additional boundary and file addition, it doesn't work. I'll get the first file...but none of the others. Help please?Current functioning code:[code=php:0]if($_GET['send'] == 1){ $from = $user['email']; $subject = $_POST['subject']; $body = stripchars($_POST['body']); $fileatt0 = $_FILES['file_attach0']['tmp_name']; $fileatt_type0 = $_FILES['file_attach0']['type']; $fileatt_name0 = $_FILES['file_attach0']['name']; $headers = 'From:'.$from." \r\n".'Reply-To:'.$from. " \r\n"; $headers .= 'Date:'.date("r")."\n"; $headers .= 'Subject: '.$subject."\n"; if (is_uploaded_file($fileatt0)) { $file0 = fopen($fileatt0,'rb'); $data0 = fread($file0,filesize($fileatt0)); fclose($file0); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n"."--{$mime_boundary}\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\n"."Content-Transfer-Encoding: 7bit\n\n".$body."\n\n"; $data0 = chunk_split(base64_encode($data0)); $message .= "--{$mime_boundary}\n"."Content-Type: {$fileatt_type0};\n"." name=\"{$fileatt_name0}\"\n"."Content-Disposition: attachment;\n"." filename=\"{$fileatt_name0}\"\n"."Content-Transfer-Encoding: base64\n\n".$data0."\n\n"."--{$mime_boundary}--\n"; $body = $message; } else { $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-Type:text/html; charset=\"iso-8859-1\" \r\n"'; } $sql = "SELECT id, email FROM user"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $id = $row['id']; if($_POST[$id] == 1) $email_list[] = $row['email']; } if(isset($subject) && isset($body) && $subject != "" && $body != "") { for($x = 0; $x < count($email_list); $x++) { $headers .= "Message-ID: <".($x + 100). "@".$_SERVER['SERVER_NAME'].">". "\r\n"; $headers .= "To: ".$row['email']." \r\n"; mail($email_list[$x], $subject, $body, $headers); if($x == 0 && count($email_list) > 1) echo("<span class=\"notification\">E-Mail sent to: ".$email_list[$x].", "); else if($x == 0 && count($email_list) == 1) echo("<span class=\"notification\">E-Mail sent to: ".$email_list[$x]."</span>"); else if($x == (count($email_list) - 1) && $x != 0) echo($email_list[$x]."</span>"); else echo($email_list[$x].", "); } } ?><form action="admin.php?tab=emailer&send=1" method="post" name="admin_emailer" enctype="multipart/form-data"> Subject:<br /><input name="subject" type="text" value="<?php echo($subject); ?>" class="longtext" maxlength="255"><br /><br /> Body:<br /><textarea name="body" cols="" rows=""><?php echo($body); ?></textarea><br /> Attachment:<input name="file_attach0" type=file><br /> <hr /> Send To:<br /> <input type="button" value="All Members" onClick="checkBox('Fat Cat');" /> <input type="button" value="All Presenters" onClick="checkBox('Presenter');" /> <input type="button" value="All Staff" onClick="checkBox('Staff/Admin');" /> <input type="button" value="Everyone" onClick="checkBox('All');" /> <br /><br /> <table> <th> </th><th> Name </th><th> Group </th><th> </th><th> Name </th><th> Group </th> //PHP Functions to Fill Table </table> <hr /> <p><input name="massmail_submit" type="submit" value="Send E-Mail"></p></form><?php[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.