AgentAlmond Posted March 14, 2014 Share Posted March 14, 2014 Hi Everyone! I'm new to php and am trying to get to a specific place an not having much luck! I (ideally) would like to be able to upload 3 image files on a webpage and have my php script resize it and then add it as 3 attachments with a load of other info in an email.... Its driving me a little insane though! I can't seem to get this code to fit with some resizing code, If you more experienced guys could point me in the right direction that would be awesome! I think i can get something in that for loop to resize as it attaches but everything i try messes up! <?php if($_POST['formSubmit'] == "Submit") { if($_POST['text_question'] == "" || $_POST['text_name'] == "" || $_POST['text_email'] == "") { header("Location: back.html"); }else{ $from = $_POST['text_email']; $to = "[email protected]"; $subject = "Website Consultation"; $message = ($_POST['text_question']); $message .= "\n----------------\n"; $message .= "From: \n" . $_POST['text_name'] . "\nE-mail address: \n" . $_POST['text_email'] . "\nPhone Number:\n" . $_POST['text_phone']; $headers = "From: " . $_POST['text_name'] . " <" . $_POST['text_email'] . ">"; $dir = "/tmp"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } // include the from email in the headers $headers = "From: $from"; // boundary $time = md5(time()); $boundary = "==Multipart_Boundary_x{$time}x"; // headers used for send attachment with email $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$boundary}\""; // multipart boundary $message = "--{$boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$boundary}\n"; // attach the attachments to the message for($x=0; $x<count($files); $x++){ $files = fopen($files[$x],"w+"); $content = fread($file,filesize($files[$x])); fclose($file); $content = chunk_split(base64_encode($content)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$filenames[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n"; $message .= "--{$boundary}\n"; } // sending mail if(@mail($to, $subject, $message, $headers)== true) { header("Location: confirm.html"); } else { header("Location: back.html"); } }} ?> Link to comment https://forums.phpfreaks.com/topic/286955-upload-temp-image-files-resize-them-and-email-as-atachments/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.