Jump to content

PHP form processor, slight image attachment issue.


INeedAGig

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.