spent all day figuring out how to attach a file to php generated email, got it working, but i can't make it html aswell!!!
I can only get one or the other to work... I know its to do with the headers
"Content-Type: multipart/mixed;\n". and to make html its
"Content-Type: html/text;\n".
how can i bring the 2 together? many thanks in advance.
<?php
$to = $POST['to'];
$from = $POST['from'];
$subject = $_POST['subject'];
$fileatt = $FILES['fileatt']['tmp_name'];
$fileatt_type = $FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "
ass.
<B>1'$territory',</B>
2'$job_title',
3'$location',
4'$media', 4b'$usage_b',
5'$term',
6'$photographer',
7'$end_user',
8'$final_approval',
9'$deadline',
12 '$currency',
13 '$budget',
14 '$other_details'";
$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-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>