reyna12 Posted December 24, 2006 Share Posted December 24, 2006 In DESPERATE NEED of a script which allows max of 5 photo uploads and sends those photos via email.I have tried one script, only sent a few of the images (out of 5) some of the time, tried something else which gets a fatal error of allowed memory size X bytes exhausted....It pulls info from a form and sends the info and image uploads (5 image upload forms in total, not all or if any at all have to be used)This is the one with fatal error,[code]<?php// Read POST request parms into global vars$email = $_POST['email'];$subject = "Caricature Details";$fullname = $_POST['fullname'];$telephone = $_POST['telephone']; $address = $_POST['address']; $postcode = $_POST['postcode']; $emailmessage = $_POST['message']; $country = $_POST['country'];$orderid = $_POST['orderid']; $website = $_POST['website']; $ThankyouURL = "thanks.php";$BadAddy = "error.php";$YourWebsiteURL = "test.php";$to = "[email protected]";// Format the message body$message = "". "Order ID: " . $orderid . "" . "Full Name: " . $fullname . "". "Email Address: " . $email . " ". "Telephone: " . $telephone . "". "Address: " . $address . "". "Postcode: " . $postcode . "". "Country: " . $country . "". "Can we use your characature on our website? " . $website . "". "How did you hear about us? " . $hear . "" . "Specification: \n\n" . $emailmessage . "";// Obtain file upload vars$fileatt = $_FILES['fileatt']['tmp_name'];$fileatt_type = $_FILES['fileatt']['type'];$fileatt_name = $_FILES['fileatt']['name'];$fileatt2 = $_FILES['fileatt2']['tmp_name'];$fileatt_type2 = $_FILES['fileatt2']['type'];$fileatt_name2 = $_FILES['fileatt2']['name'];$fileatt3 = $_FILES['fileatt3']['tmp_name'];$fileatt_type3 = $_FILES['fileatt3']['type'];$fileatt_name3 = $_FILES['fileatt3']['name'];$fileatt4 = $_FILES['fileatt4']['tmp_name'];$fileatt_type4 = $_FILES['fileatt4']['type'];$fileatt_name4 = $_FILES['fileatt4']['name'];$fileatt5 = $_FILES['fileatt5']['tmp_name'];$fileatt_type5 = $_FILES['fileatt5']['type'];$fileatt_name5 = $_FILES['fileatt5']['name'];$headers = "From: $email";if (is_uploaded_file($fileatt) || is_uploaded_file($fileatt2) || is_uploaded_file($fileatt3) || is_uploaded_file($fileatt4) || is_uploaded_file($fileatt5)) { // Read the file to be attached ('rb' = read binary) if (is_uploaded_file($fileatt)) { $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Base64 encode the file data $data = chunk_split(base64_encode($data)); } if (is_uploaded_file($fileatt2)) { $file2 = fopen($fileatt2,'rb'); $data2 = fread($file2,filesize($fileatt2)); fclose($file2); // Base64 encode the file data $data2 = chunk_split(base64_encode($data2)); } if (is_uploaded_file($fileatt3)) { $file3 = fopen($fileatt3,'rb'); $data3 = fread($file3,filesize($fileatt3)); fclose($file3); // Base64 encode the file data $data3 = chunk_split(base64_encode($data3)); } if (is_uploaded_file($fileatt4)) { $file4 = fopen($fileatt4,'rb'); $data4 = fread($file4,filesize($fileatt4)); fclose($file4); // Base64 encode the file data $data4 = chunk_split(base64_encode($data4)); } if (is_uploaded_file($fileatt5)) { $file5 = fopen($fileatt5,'rb'); $data5 = fread($file5,filesize($fileatt5)); fclose($file5); // Base64 encode the file data $data5 = chunk_split(base64_encode($data5)); } // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain;\n charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n" . "--{$mime_boundary}\n"; // Add file attachment(s) to the message if ($fileatt_name > "") { $message .= "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n\n" . $data . "\n" . "--{$mime_boundary}\n"; } if ($fileatt_name2 > "") { $message .= "Content-Type: {$fileatt_type2};\n" . " name=\"{$fileatt_name2}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name2}\"\n\n" . $data2 . "\n" . "--{$mime_boundary}\n"; } if ($fileatt_name3 > "") { $message .= "Content-Type: {$fileatt_type3};\n" . " name=\"{$fileatt_name3}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name3}\"\n\n" . $data3 . "\n" . "--{$mime_boundary}\n"; } if ($fileatt_name4 > "") { $message .= "Content-Type: {$fileatt_type4};\n" . " name=\"{$fileatt_name4}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name4}\"\n\n" . $data4 . "\n" . "--{$mime_boundary}\n"; } if ($fileatt_name5 > "") { $message .= "Content-Type: {$fileatt_type5};\n" . " name=\"{$fileatt_name5}\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name5}\"\n\n" . $data5 . "\n" . "--{$mime_boundary}"; } $message .= "--\n\n"; }//Validate the email address usedif (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $_POST['email'])) { // Send the message $ok = @mail("$to", $subject, $message, $headers); if ($ok) { header("Location: $ThankyouURL"); } else { echo "<p>Mail could not be sent. Sorry!</p>"; }}else { header("Location: $BadAddy");}?>[/code]Thanks :) Link to comment https://forums.phpfreaks.com/topic/31769-image-upload-send-to-email/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.