Forum Moderators: coopster
I have re-written the previous code used in the previous post with what I have leaned about MIME and attaching a file with a php form for e-mail
From what I have learned the code I worte below should be working, and it does, except it will still not send the e-mail attachment?
It all seems right to me? Can someone tell me why its not working? Thanks
$paid = $HTTP_POST_VARS['paid']; $to = "example@example.com"; // Obtain file upload vars $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Generate a boundary string // Add a multipart boundary above the plain message // Base64 encode the file data // Add file attachment to the message // Send the message
<?php
$lovedby = $HTTP_POST_VARS['description'];
$caption = $HTTP_POST_VARS['submitted'];
$city = $HTTP_POST_VARS['city'];
$state = $HTTP_POST_VARS['state'];
$month = $HTTP_POST_VARS['month'];
$day = $HTTP_POST_VARS['day'];
$year = $HTTP_POST_VARS['year'];
$from = $HTTP_POST_VARS['from'];
$subject = "$month $day $year";
$message = "
Loved By:$lovedby
Caption:$caption
City:$city
State:$state
Month:$month
Day:$day
Year:$year ";
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$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/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
it says
Undefined index: fileatt in www.exaple.com/ / on line 46
Undefined index: fileatt in www.exaple.com/ / on line 47
Undefined index: fileatt in www.exaple.com/ / on line 48
fileatt is the name of the browse box in the form where the user can select the file for e-mail. What does this mean?