duanjizi9443 2018-06-18 14:43
浏览 118
已采纳

Php在希腊语中发送名称附件

I am using php mail function to send an email with a pdf attachment, but its name which is written in greek does not show correctly. I have tried many different things but nothing worked.

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);

The result I get is ΤÎ%c2 greek chars.pdf. Could anyone figure out what is wrong

  • 写回答

1条回答 默认 最新

  • doujiao6116 2018-06-18 15:00
    关注

    As per Mail_Mime::addAttachment() documentation, you may specify the encoding of the attachment's name.

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

    So, you can modify your addAttachement function as:

    $mime->addAttachment($file, 'application/pdf', $filename, true, 'base64', 'attachment', '', '', '', 'utf-8');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答