当附件文件名以希腊字符开头时,PHPMailer 正在截断附件文件名
PHPMailer is cutting the attachement filename when it starts with a greek character
我使用 PHPMailer 附加 Excel 文件并通过邮件发送它们。
创建的文件格式为 "street address"-"month" 希腊字符。
我想到的第一个问题是附件的文件名字符不可读,所以我从 base64.
更改了 phpmailer class $CharSet = 'UTF-8';
在我的本地主机 (XAMPP) 上 运行 很好,邮件以正确的文件名发送。
但是当我在 Linux 服务器上使用相同的代码时,虽然文件是用正确的文件名创建的,但是当我附加它时,文件名被剪切到第一个数字、拉丁字符或破折号。
该文件的内容和可读性是一样的。唯一的问题是文件名。
例如Οδός - Μìρτιος --> - Μìρτιος , 1 Οδός - ΜΙρτιος --> 1 Οδός - Μìρτιος
...
$outputFileType = 'Excel2007';
$outputFileName = dirname(__FILE__).'/'.$address.' - '.$period.'.xlsx';
$objWriter->save($outputFileName);
...
$mail->AddAttachment($outputFileName);
更新 1
在将 class.phpmailer.php 中的 $attachment 属性 更改为 public 之后,我在 AddAttachment 函数之后打印了数组.我得到了
Array ( [0] => Array (
[0] => /var/www/vhosts/domain.com/wp-content/themes/My-Theme/Reports/Οδός 1 - Μήνας 2014.xlsx
[1] => 1 - Μήνας 2014.xlsx
[2] => 1 - Μήνας 2014.xlsx
[3] => base64
[4] => application/octet-stream
[5] =>
[6] => attachment
[7] => 0 ) )
所以我猜 AddAttachment 函数有问题。路径(附件[0])是对的
问题是 AddAttachment() 使用 basename() 从路径中提取文件名并且 basename 是区域设置感知的。
希腊用户必须在 class.phpmailer.php 文件中添加 setlocale(LC_ALL, 'greek');
。
我使用 PHPMailer 附加 Excel 文件并通过邮件发送它们。
创建的文件格式为 "street address"-"month" 希腊字符。
我想到的第一个问题是附件的文件名字符不可读,所以我从 base64.
更改了 phpmailer class $CharSet = 'UTF-8';
在我的本地主机 (XAMPP) 上 运行 很好,邮件以正确的文件名发送。
但是当我在 Linux 服务器上使用相同的代码时,虽然文件是用正确的文件名创建的,但是当我附加它时,文件名被剪切到第一个数字、拉丁字符或破折号。
该文件的内容和可读性是一样的。唯一的问题是文件名。
例如Οδός - Μìρτιος --> - Μìρτιος , 1 Οδός - ΜΙρτιος --> 1 Οδός - Μìρτιος
...
$outputFileType = 'Excel2007';
$outputFileName = dirname(__FILE__).'/'.$address.' - '.$period.'.xlsx';
$objWriter->save($outputFileName);
...
$mail->AddAttachment($outputFileName);
更新 1
在将 class.phpmailer.php 中的 $attachment 属性 更改为 public 之后,我在 AddAttachment 函数之后打印了数组.我得到了
Array ( [0] => Array (
[0] => /var/www/vhosts/domain.com/wp-content/themes/My-Theme/Reports/Οδός 1 - Μήνας 2014.xlsx
[1] => 1 - Μήνας 2014.xlsx
[2] => 1 - Μήνας 2014.xlsx
[3] => base64
[4] => application/octet-stream
[5] =>
[6] => attachment
[7] => 0 ) )
所以我猜 AddAttachment 函数有问题。路径(附件[0])是对的
问题是 AddAttachment() 使用 basename() 从路径中提取文件名并且 basename 是区域设置感知的。
希腊用户必须在 class.phpmailer.php 文件中添加 setlocale(LC_ALL, 'greek');
。