I am sending form data through a .swf file into this PHP page.(see below) When the email is sent, if there is an attachment the body of the message will not appear but if there is not an attachment the body appears just fine. I know that all of the variable names are correct because all of the data has been passed from the swf file. Is there something in the way I have set up the email that makes it work that way? Please let me know.
<?php
$to=$_POST['toEmail'];
$subject=$_POST['subject'];
$body = $_POST['messaggio'];
$nome = $_POST['nome'];
$email = $_POST['email'];
$attach = $_POST['attach'];
$headers = "From: $nome<" . $email . ">\n";
if ($attach == 1) {
$tmp_name = $_FILES['Filedata']['tmp_name'];
$type = $_FILES['Filedata']['type'];
$name = $_FILES['Filedata']['name'];
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
$headers .= "Reply-To: <" . $email . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDARY_main_message\"\n";
$headers .= "X-Sender: $to <" . $to . ">\n";
$headers .= "Return-Path: <" . $email . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDARY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDARY_message_parts\"\n";
$message = "------=MIME_BOUNDARY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= $body . "\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_message_parts--\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message\n";
$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $name . "\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $name . "\"\n\n";
$message .= $data;
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message--\n";
mail($to, $subject, $message, $headers);
}
} else {
if(mail($to, $subject, $body, $headers)) {
echo "ok=1";
}
}
?>