【问题标题】:Php send attachment with name in greekphp发送带有希腊名称的附件
【发布时间】: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


【解决方案1】:

根据 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');

【讨论】:

  • 是的,我在我的代码中使用了它并且它有效:$mime->addAttachment($file, 'application/pdf', $filename, true, 'base64', 'attachment', 'utf- 8', '', '', '');谢谢
  • @JohnPadiou 很高兴为您提供帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-03
  • 2023-03-21
  • 1970-01-01
  • 2013-06-20
相关资源
最近更新 更多