Php发送带有希腊语名称的附件
我正在使用php邮件功能发送一封带有pdf附件的电子邮件,但其名称(用希腊语书写)显示不正确。我尝试过很多不同的方法,但都没有效果Php发送带有希腊语名称的附件,php,email,encoding,attachment,Php,Email,Encoding,Attachment,我正在使用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@tes
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希腊文chars.pdf。如果有人能找出问题所在根据Mail_Mime::addAttachment()文档,您可以指定附件名称的编码 因此,您可以将
addAttachement
函数修改为:
$mime->addAttachment($file, 'application/pdf', $filename, true, 'base64', 'attachment', '', '', '', 'utf-8');
可能重复使用$filename的位置?$filename和$file是否相同?$filename是硬编码的还是从数据库中获取的?对不起,我是说我编辑了它$filename@Script47,但我没有从mysql获取文件名…是的,我在代码中使用了它:$mime->addAttachment($file,'application/pdf',$filename,true,'base64','attachment','utf-8','','','';Thanks@JohnPadiou很高兴帮助您:)