Php 发送名称为希腊文的附件

Php send attachment with name in greek

我正在使用 php 邮件功能发送带有 pdf 附件的电子邮件,但它的希腊文名称显示不正确。我尝试了很多不同的方法,但没有任何效果。

require_once "/usr/share/pear/Mail.php";
require_once "/usr/share/pear/Mail/mime.php";
$filename= "ΤΠΥ ΗΛ ΚΛΠ greek chars.pdf";

$mailBody = 'lorem ipsum blah blah';

$from = 'test@test.gr';
$to = 'test2@test2.gr';

//email settings from database (it is working correctly)
$smtp = Mail::factory('smtp',array ('host' => $emailSettings['host'],'port'=> $emailSettings['port'],'auth' => $auth,'username' => $emailSettings['username'],'password' => $emailSettings['password']));

$hdrs = array ('From' => $from,
                'To' => $to,
              'Subject' => $emailMessages['subject'],
             'Content-Type'  => 'text/html; charset=UTF-8');
$mime_params = array(
  'text_encoding' => '7bit',
  'text_charset'  => 'utf-8',
  'html_charset'  => 'utf-8',
  'head_charset'  => 'utf-8'
);        
$mime = new Mail_mime();          
$mime->setHTMLBody($mailBody);
$mime->addAttachment($filename, 'application/pdf');

$body = $mime->get($mime_params);
$hdrs = $mime->headers($hdrs);
$mail = $smtp->send($to, $hdrs, $body);

我得到的结果是 εε%c2 greek chars.pdf。谁能找出问题所在

根据 Mail_Mime::addAttachment() 文档,您可以指定附件名称的编码。

https://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php

因此,您可以将 addAttachement 函数修改为:

$mime->addAttachment($file, 'application/pdf', $filename, true, 'base64', 'attachment', '', '', '', 'utf-8');