В прошлой теме проблему решил, но в этот раз письмо с вложением, и письмо попадает в спам — почему?
function send_mail($admin, $body, $email, $filepath, $filename)
{
$subject = '=?UTF-8?B?'.base64_encode('Заполнена форма на сайте').'?=';
$boundary = "--".md5(uniqid(time())); // генерируем разделитель
$headers = "From: ".strtoupper($_SERVER['SERVER_NAME'])." <".$email.">\r\n";
$headers .= "Return-path: <".$email.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n";
$multipart = "--".$boundary."\r\n";
$multipart .= "Content-type: text/plain; charset=\"UTF-8\"\r\n";
$multipart .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
$body = quoted_printable_encode( $body )."\r\n\r\n";
$multipart .= $body;
$file = '';
if ( !empty( $filepath ) ) {
$fp = fopen($filepath, "r");
if ( $fp ) {
$content = fread($fp, filesize($filepath));
fclose($fp);
$file .= "--".$boundary."\r\n";
$file .= "Content-Type: application/octet-stream\r\n";
$file .= "Content-Transfer-Encoding: base64\r\n";
$file .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$file .= chunk_split(base64_encode($content))."\r\n";
}
}
$multipart .= $file."--".$boundary."--\r\n";
if( mail($admin, $subject, $multipart, $headers) )
return true;
else
return false;
}