I've been struggling to find any simple to follow guides or tutorials on how to do this so I thought I would ask here. I am sending out an email and all I want to do is attach 2 pdf files to it. I have found a script that allows me to send a single email with a single attachment.
This works fine but how can I adapt this to send 2 attachments? Here's the code for the form that gets the user info;Code:<?php $from = "me@domain.com"; $to = $_POST['email']; $subject = "Uploaded file"; $mail_body = "Message body"; $fileatt = $_FILES['file']['tmp_name']; $fileatt_type = $_FILES['file']['type']; $fileatt_name = $_FILES['file']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { $file= fopen($fileatt, 'rb'); $data = fread($file, filesize($fileatt)); $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}\""; $mail_body = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $mail_body . "\n\n"; $data = chunk_split( base64_encode($data)); $mail_body .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; $ok = @mail($to, $subject, $mail_body, $headers); if($ok) echo "Email sent :)"; else echo "Failed !!!"; fclose($file); } ?>
If anyone can help or point me in the right direction, then I would be very grateful.Code:<form action="process.php" method="post" enctype="multipart/form-data"> To:<input type="text" name="email" /><br /> File: <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Sent" /> </form>



Reply With Quote

Bookmarks