Ok I must have used the incorrect script, I have a mail folder on my server with all sorts of scripts. I ran the script posted to no avail...then I got mad and could not remember what I had called it. In the case of what you are doing basically uploading to a form I went over other scripts and came up with one that will upload an image with a form then send it as an inline attachment. You have to use HTML in the message (textarea of the form) to specify the inline images where you want them to display. The code I will post works if you properly sode the message with <img src="yourfile.jpg"> or whatever. I have been working on this since this morning.
Like I stated earlier MIME e-mail with HTML and attachments are complex and hard to understand especially when you are wanting to have more than one of them. The form part is no problem but the processing of MIME mail is where the confusion comes in. I have commented this code in the processing page so maybe it will make some sense, anyway it does work so here is a code to try out and see if it doesn't work for what you need.
HTML form:
<html>
<head>
<title>Send an Email with inline attachment</title>
</head>
<body>
<h2>Send an Email with an inline attachment</h2>
You will have to use the proper HTML tags for sending the image. <br />When entering just enter the actual filename not anything else, this is taken care of by the script. <br />Example <:img src='somepic.jpg'>
<form action="testattach2.php" method="POST" enctype="multipart/form-data">
<p>To: <input type="text" name="to" value="" /><br />
From: <input type="text" name="from" value="" /><br />
Subject: <input type="text" name="subject" value="" /></p>
<p>Message:<br />
<textarea cols="70" rows="15" name="message"></textarea></p>
<p>File Attachment 1: <input type="file" name="fileatt" /></p>
<p>File Attachment 2: <input type="file" name="fileatt2" /></p>
<p><input type="submit" value="Send" /></p>
</form>
</body>
</html>
testattach2.php
<?php
//create short variables from form array variables
$from=trim($_POST['from']);
$subject=trim($_POST['subject']);
$to=trim($_POST['to']);
$html2=$_POST['message'];
$html2=stripslashes($html2);
//set up the headers for the from
$headers = "From: $from";
//the below is your own plain text message (all the $message(x))*/
$message12 = "This is the plain test message because your e-mail doesn't support HTML";//add more if you want
//Now lets set up the attachments from the form (first file attachment image)
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
//next file attachment image***************************************
$fileatt2 = $_FILES['fileatt2']['tmp_name'];
$fileatt_type2 = $_FILES['fileatt2']['type'];
$fileatt_name2 = $_FILES['fileatt2']['name'];
//first check for uploaded files (first file).
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
}
//check second and other files (repeat as necessary.)
if (is_uploaded_file($fileatt2)) {
// Read the file to be attached ('rb' = read binary)
$file2 = fopen($fileatt2,'rb');
$data2 = fread($file2,filesize($fileatt2));
fclose($file2);
}
// Now generate a boundary string that is unique
$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/alternative;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"<font face=Arial>" .
$html2."\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message12 . "\n\n";
// Add the headers for a file attachment (plain text)
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message (image attachment)
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" . // {$fileatt_type}
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: inline;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// Base64 encode the second and subsequent file data
$data2 = chunk_split(base64_encode($data2));
// Add file attachment to the message (image attachment)
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type2};\n" . // {$fileatt_type}
" name=\"{$fileatt_name2}\"\n" .
"Content-Disposition: inline;\n" .
" filename=\"{$fileatt_name2}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data2 . "\n\n" .
"--{$mime_boundary}--\n";
//now lets send the file via the mail()function.
$send = mail($to, $subject, $message, $headers);
if ($send) {
echo "<p>Email Sent to intended recipient successfully!</p>";
} else {
echo "<p>Mail could not be sent. You missed something in the script. Sorry!</p>";
}
?>