Php mail ile ekli dosya gönderme
function mail_dosya( $gidenmailadresi, $mailbaslik, $mailhtml, $gönderilenmailadresi, $eklenendosya, $replayadresi=”” ) {
// handles mime type for better receiving
$ext = strrchr( $eklenendosya , ‘.’);
$ftype = “”;
if ($ext == “.doc”) $ftype = “application/msword”;
if ($ext == “.jpg”) $ftype = “image/jpeg”;
if ($ext == “.gif”) $ftype = “image/gif”;
if ($ext == “.zip”) $ftype = “application/zip”;
if ($ext == “.pdf”) $ftype = “application/pdf”;
if ($ftype==””) $ftype = “application/octet-stream”;
$file = fopen($eklenendosya, “rb”);
$data = fread($file, filesize( $eklenendosya ) );
fclose($file);
$content = chunk_split(base64_encode($data));
$uid = md5(uniqid(time()));
$h = “From: $gönderilenmailadresi\r\n”;
if ($replayadresi) $h .= “Reply-To: “.$replayadresi.”\r\n”;
$h .= “MIME-Version: 1.0\r\n”;
$h .= “Content-Type: multipart/mixed; boundary=\””.$uid.”\”\r\n\r\n”;
$h .= “This is a multi-part message in MIME format.\r\n”;
$h .= “–“.$uid.”\r\n”;
$h .= “Content-type:text/html; charset=iso-8859-1\r\n”;
$h .= “Content-Transfer-Encoding: 7bit\r\n\r\n”;
$h .= $mailhtml.”\r\n\r\n”;
$h .= “–“.$uid.”\r\n”;
$h .= “Content-Type: “.$ftype.”; name=\””.basename($eklenendosya).”\”\r\n”;
$h .= “Content-Transfer-Encoding: base64\r\n”;
$h .= “Content-Disposition: attachment; filename=\””.basename($eklenendosya).”\”\r\n\r\n”;
$h .= $content.”\r\n\r\n”;
$h .= “–“.$uid.”–“;
// mail gönder
return mail( $gidenmailadresi, $mailbaslik, strip_tags($mailhtml), str_replace(“\r\n”,”\n”,$h) ) ;
}