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 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法