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!

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.