INeedAGig Posted March 18, 2012 Share Posted March 18, 2012 Hey guys, I am adding to my current php form processor and I need it to be able to support image uploads, that also show up as an attachment in the email with the rest of the form data. The only part I am having problems with is getting the image to work as an attachment in the email, at the moment, it is not showing up at all in the email but it is successful at showing up on the web server (which I have it doing for storage reasons). I have attached the code involved for the image processing portion, an also a snippet of code showing how the emails are sent. This code is for the image attachment processing <?php //Get the uploaded file information $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); //Get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs //Settings $max_allowed_file_size = 150; // size in KB $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png"); //Validations if($size_of_uploaded_file > $max_allowed_file_size ) { $errors .= "\n File size too large! Max file size alowed is $max_allowed_file_size"; } //------ Validate the file extension ----- $allowed_ext = false; for($i=0; $i<sizeof($allowed_extensions); $i++) { if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0) { $allowed_ext = true; } } if(!$allowed_ext) { $errors .= "\n The uploaded file is not supported file type. ". " Only the following file types are supported: ".implode(',',$allowed_extensions); } //Copy the temp. uploaded file to server $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["uploaded_file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n Error while copying the uploaded file'; } } ?> This is the header setup for sending the email, which for some reason I think i am missing something here, causing the image to not show up in the email. $headers = "From: edited_out_for_this_post@edited_out_for_this_post.com\r\n"; $headers .= "Reply-To: no-reply@edited_out_for_this_post.com\r\n"; $headers .= "Return-Path: no-reply@edited_out_for_this_post.com\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Thanks for your help in advance! Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/ Share on other sites More sharing options...
INeedAGig Posted March 19, 2012 Author Share Posted March 19, 2012 I'm still having some trouble with this, any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/#findComment-1328883 Share on other sites More sharing options...
INeedAGig Posted March 19, 2012 Author Share Posted March 19, 2012 Hey there guys, I am still having some trouble solving this issue, any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/#findComment-1329203 Share on other sites More sharing options...
INeedAGig Posted March 20, 2012 Author Share Posted March 20, 2012 I have added a MIME type to the headers, still no luck, any ideas?? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/#findComment-1329649 Share on other sites More sharing options...
rythemton Posted March 20, 2012 Share Posted March 20, 2012 To include images, there are two methods: included in the email or linked to files on your web server. Linked to files on your web server is easiest, since you just include the full address to the image on your web server. Included in the email requires a multi-part content type, and requires encoding the image. The following has some example code: http://webcheatsheet.com/PHP/send_email_text_html_attachment.php Good Luck! Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/#findComment-1329666 Share on other sites More sharing options...
INeedAGig Posted March 21, 2012 Author Share Posted March 21, 2012 Thanks for your reply, but, is there anything I can add to my current script to get it working properly? Quote Link to comment https://forums.phpfreaks.com/topic/259224-php-form-processor-slight-image-attachment-issue/#findComment-1329677 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.