【发布时间】:2018-06-18 14:43:43
【问题描述】:
我正在使用 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。谁能弄清楚是什么问题
【问题讨论】:
-
你在哪里使用 $filename? $filename 和 $file 一样吗? $filename 是硬编码的还是从数据库中获取的?
-
对不起,我编辑了它,我的意思是 $filename
-
@Script47,虽然我没有从 mysql 获取文件名...
标签: php email encoding attachment