$msg = "message";
$file = 'https://site.ru/assets/templates/images/4.png';
$file_size = filesize($file);
$handle = fopen($file, "r");
$content_attachment = fread($handle, $file_size);
$type = mime_content_type($file);
fclose($handle);
$content_attachment = chunk_split(base64_encode($content_attachment));
$uid = md5(uniqid(time()));
$name = basename($file);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n"; // multipart/mixed
// $headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "From: ".$_SERVER['HTTP_HOST']." <site@".$_SERVER['HTTP_HOST'].">\r\n";
$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content .= "--".$uid."\r\n";
$content .= "Content-Type:text/html; charset=utf-8\r\n";
$content .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content .= $msg."\r\n\r\n";
$content .= "--".$uid."\r\n";
$content .= "Content-Type: $type; name=\"".$filename."\"\r\n";
$content .= "Content-Transfer-Encoding: base64\r\n\r\n";
$content .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$content .= $content_attachment."\r\n\r\n";
$content .= "--".$uid."--";
mail($emails,"$title $site_name {$_POST['forma']}", $content, $headers);