我正在尝试使用 PHP mail() 函数发送带有附件的电子邮件。电子邮件已送达,但在网络邮件中,文件名显示为“无标题”。使用 Outlook Avast 启发式完全阻止电子邮件。
请指导我克服这个问题。
这是我正在使用的代码
$recieverAdd = 'r@gamil.com';
$subject = 'Attachment';
$attDescription="emailing lessons";
$filename ='example.pdf';
$file = '/home/user/example.pdf';
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$from_name = $uname;
$from_mail = 'admin@gmail.com';
$replyto ='noreply@gmail.com';
$header = "From: $from_name";
$header .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$uid}\"";
$message = "<p><b>Hello </b></p>";
$messageBody = "--{$uid}\n" . "Content-Type: text/html; charset=\"iso-8859-1 \"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$messageBody .= "--{$uid}\n". "Content-Type: application/octet-stream;\n".
"name=\"{$filename1}\"\n".
"Content-Description: {$filename}\n" .
"Content-Disposition: attachment;\n".
"filename=\"{$filename}\"; size={$file_size};\n" .
"Content-Transfer-Encoding: base64\n\n". $content."\n\n". "--{$uid}--\n";
mail($recieverAdd,$subject,$messageBody,$header)