Hi guys, I'm new to php and I really need your help.
Below is a rather short php code for a formmail with the ability to attach a file.
<?php
if($mode=='mailsend')
{
$to = 'my@email.com' ;
$subject = "You've got mail!";
$header .= "Return-Path: $from\r\n";
$header .= "From: $name <$from>\r\n";
$header .= "X-Mailer: chfeedback.php 2.07";
if ($userfile && $userfile_size) {
$filename=basename($userfile_name);
$result=fopen($userfile,"r");
$file=fread($result,$userfile_size);
fclose($result);
if ($userfile_type == "")
{
$userfile_type = "application/octet-stream";
}
$boundary = "--------" . uniqid("part");
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
$message = "This is a multi-part message in MIME format.\r\n\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-Type: text/html; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$message .= "New email has arrived.\r\n--------------------------------------------\r\nTitle: ";
$message .= nl2br(stripslashes($title)). "\r\n---------------------------------------------\r\n\r\n";
$message .= nl2br(stripslashes($msg)) . "\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-Type: $userfile_type; name=\"$filename\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n\r\n";
$message .= ereg_replace("(.{80})","\\1\r\n",base64_encode($file));
$message .= "\r\n--$boundary" . "\r\n";
}
else {
$message .= "New email has arrived.\r\n--------------------------------------------\r\nTitle: ";
$message .= stripslashes($title). "\r\n---------------------------------------------\r\n\r\n";
$message .= stripslashes($msg) . "\r\n";
}
mail($to,$subject,$message,$header);
echo(" <meta http-equiv='Refresh' content='0; URL=./success.html'>");
exit;
}
?>
I get a normal email when there's no file attached to it,
but when a file's attached, the mail body won't show right.
(seems like it doesn't recognize the \r\n part)
And I have no idea what's causing this problem.
It'd be great if you guys could guide me through this.
Thanks in advance,
ketchup