Hey everyone, got a little problem and I can't seem to figure out what the problem is. I have made a short page where people can enter an email address and select a file to be sent to them. I have pillaged some code from some previous posts here which was very helpful. The script works more or less, however I have 2 problems:
1) The HTML isn't picked up in the body of the email, however the text is.
2) The attachment makes it to the email however when you open it up, its a blank file.
Here is my code. I've also made sure the selected files are 777 on the server. If someone could take a quick gander, I'd really appreciate it! Thanx much!
Nico
<?
if($submit) {
$to = "$remail";
$subject = "Drivers";
$from = "Tech Support <noreply@noreply.com>";
$file = "$driver";
$floc = "/var/www/html/docs/drivers";
$bname = "tech";
$timer = time();
$bound = "00-".$bname."-".$timer."";
$stime = date("r",time());
$headers = "Date: ".$stime."\n";
$headers.= "From: ".$from."\n";
$headers .= "To: ".$to."\n";
$headers .= "X-Priority: 1 (High)\n";
$headers .= "X-Mailer: <PHP MAILER>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$bound\"\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$msg .= "<html><head><title>Uniden Drivers</title></head><body>\n";
$msg .=" \n";
$msg .="<tr><td>Here are the drivers you requested. td></tr>\n";
$msg .="<tr><td>Please do not reply to this email address; we will not receive any responses.</td></tr>\n";
$msg .="</body></html>\n";
$message = "--".$bound."";
$message .= "\n";
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= "$msg";
$message .= "\n";
$message .= "\n";
$message .= "\n";
$ahead = "--".$bound."";
$ahead .= "\n";
$ahead .= "Content-Type: application/octet-stream\n";
$ahead .= "Content-Transfer-Encoding: base64\n";
$ahead .= "Content-Disposition: attachment; filename=\"$file\"\n";
set_magic_quotes_runtime(0);
$attachment = fread(fopen("$floc/$file", "rb"), filesize("$floc/$file"));
$attachment = chunk_split(base64_encode($attachment));
$attachment = preg_replace("/\n/i", "\n", $attachment);
$ahead .= "$attachment";
$ahead .= "\n";
$message .= "$ahead";
set_magic_quotes_runtime(get_magic_quotes_gpc());
$message .= "--".$bound."--";
mail($to, $subject, $message, $headers)
or die("error sending mail");
}
?>