我使用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。任何人都可以找出问题所在
答案 0 :(得分:0)
根据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');