PHP mailform with attachement

I’ve got a mailform wich can send attachements aswell, but when i send an image as attachement, i dont receive the image in my mail, but i receive the code of the image in my email… when i send a .doc it does work… here is my code… who can tell me what’s wrong… (i guess something with the content-type…)

 
<? 

/** Email Form with Attachement 

by Floris van der Ploeg 

Little modyfication by Peter Buijsse 



to work with php v3 



*/ 

if ($action == "send")

 

 

{ 

$body .= "naam: $name<BR>";

$body .= "email: $from<BR>";

$body .= "kleur: $veld<BR>";

$body .= "bericht: $text<BR>";

print $body;

$header = "From: " . $from . "
"; 

if ($check == "yes") 

{ 

// Get attachement type 

$type = $attachement_type; 

//echo "type=$type<br>"; 



if (($type == "text/plain") || ($type == "text/html")) 

$encoding = "8bit"; 

else 

$encoding = "base64"; 

 

 

// Get attachement content 

$fp = @fopen($attachement,"r"); 

 

//echo "fp=$fp<br>"; 

//echo "bestandsnaam=$attachement<br>"; 

if (!$fp) { 

print "Could not open attachment for reading...<br>
"; 

print "Exiting script!<br><br>"; 

print "No mail has been sent!"; 

exit; 

} 

$file_content = fread($fp,filesize($attachement)); 

 

 

// if encoding is base64 ... encode it 

if ($encoding == "base64") 

$file_content = chunk_split(base64_encode($file_content)); 

 

 

// create a unqiue boundary 

$boundary = strtoupper(md5(uniqid(time()))); 

 

 

// create the message header... 

$header .= "MIME-version: 1.0
"; 

$header .= "Content-Type: multipart/mixed;
"; 

$header .= "	boundary= " . $boundary . "

"; 

 

 

$header .= "This is a multi-part message in MIME format.

"; 

 

 

// create the message body in the header 

$header .= "--" . $boundary . "
"; 

$header .= "Content-Type: " . $ct . ";
"; 

$header .= "	charset=\"iso-8859-1\"
"; 

$header .= "Content-Transfer-Encoding: ".$ct."

";

 

 

// actual message 

$header .= "bericht: " . $body; 

 

 

// now for the attachement 

$header .= "--" . $boundary . "
"; 

$header .= "Content-Type: " . $type . "
"; 

$header .= "Content-Transfer-Encoding: " . $encoding . "
"; 

$header .= "Content-Disposition: attachment; filename=\"" . $attachement_name . "\"

"; 

 

 

// actual attachement 

$header .= $file_content . "

"; 

$header .= "--" . $boundary . "--";

} 

else // if there is no attachement... 

{ 

$header .= "Content-Type: " . $ct . ";
"; 

$header .= "	charset=\"iso-8859-1\"
"; 

$header .= "Content-Transfer-Encoding: quoted-printable

"; 

 

 

// actual message 

$header .= "bericht: " . $body . "

"; 

} 

if (@mail("[email protected]","bestelling","",$header)) 

print "Mail sent!"; 

else 

print "Error sending email!"; 

 

 

} 

else 

{

?> 

<html> 

<head>

<SCRIPT LANGUAGE="JavaScript">

<!--

function verander() {

alert("test");

document.getElementById('bestand').value = "yes";

help = document.getElementById('bestand').value;

alert(help);

}

// -->

</SCRIPT>

<title>Mail Attachement</title> 

</head> 

<body bgcolor="#FFFFFF"> 

<center> 

<form enctype="multipart/form-data" action="test2.php" method="POST" id="test"> 

<input type="hidden" name="action" value="send">

<input type="hidden" name="check" value="no" id = "bestand">

<table width="500" cellspacing="0" cellpadding="0" border="0"> 

<tr> 

<td width="150" align="left" valign="center"> 

<font face="Verdana,Tahoma,Arial,Helvetica" size="2">naam:<br>

e-mail:<br>

ander veld:</font></td> 

<td width="350" align="left" valign="center"> 

<input type="text" name="name" size="40"><br>

<input type="text" size="40" name="from"> 

<br>

<select size="1" name="veld">

<option selected>kies een kleur</option>

<option value="rood">rood</option>

<option value="blauw">blauw</option>

<option value="paars">paars</option>

<option value="oranje">oranje</option>

</select></td> 

</tr> 

<tr> 

<td width="150" align="left" valign="center"> 

<font face="Verdana,Tahoma,Arial,Helvetica" size="2">opmaak:</font></td> 

<td width="350" align="left" valign="center"> 

<select name="ct"> 

<option value="text/plain">Plaintext</option> 

<option value="text/html">HTML mail</option> 

</select> 

</td> 

</tr> 

<tr> 

<td width="150" align="left" valign="top"> 

<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000"> 

bericht: 

</font> 

</td> 

<td width="350" align="left" valign="top"> 

<textarea rows="8" cols="38" name="text"></textarea> 

</td> 

</tr> 

<tr> 

<td width="150" align="left" valign="center"> 

<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000"> 

Attachement: 

</font> 

</td> 

<td width="350" align="left" valign="center"> 

<input type="file" name="attachement" onchange="verander()"> 

</td> 

</tr> 

<tr> 

<td width="150" align="left" valign="center"> 

<font face="Verdana,Tahoma,Arial,Helvetica" size="2" color="#000000"> 

</font> 

</td> 

<td width="350" align="left" valign="center"> 

<input type="submit" value="Send"> 

</td> 

</tr> 

</table> 

</center> 

</body></html>

<? 

} 

?>