here is a sample code to send a mail with an attachement !
$sendto = "albo_le_tono@yahoo.com\n";
$sender= "From: $email\n";
$subjet="personnes à contacter";
$recipient="the content of your mail\n";
$filetoattach = "example.txt";
$size = filesize($filetoattach);
$type = filetype($filetoattach);
// get the content of the file in a string
$PtrAttachedFile = @fopen($filetoattach,"r");
$StrAttachedFile = @fread($PtrAttachedFile, $size);
@fclose($PtrAttachedFile);
//base64 encoding. Because the file must be in this format to be sent with a mail client
$FileToAttach64 = base64_encode($StrAttachedFile);
//RFC 2045 norm
$FileToAttach64 = chunk_split($FileToAttach, 64 , "\r\n");
//Creation of the header. The "--some random text " string is to mark the file to send. It is used later in the $sender.
$HeaderAttachedFile = "\n--some random text\nContent-Type: ".$type.";\n name=\"".$fichier."\"\n"."Content-Transfer-Encoding: base64\nContent-Disposition: attachment;\n filename=\"".$fichier."\"\n\n";
// we specify the attachement in the recipient
$recipient .= $HeaderAttachedFile.$FileToAttach64;
// we add the attachemnt header in the sender header
//chr(13) is a carriage return, chr(10) a line jump and chr(9) a tabulation
$sender .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;".chr(13).chr(10).chr(9)."boundary=\"some random text\"\n";
mail($sento, $subjet, $recipient, $sender);
unlink("example.txt");// erase the file
}