问题描述
我在 Yii 应用程序中使用 SwiftMailer 插件来发送电子邮件。电子邮件成功发送,带附件和不带附件。但是,我注意到如果附件文件名太长,它会被编码。如果文件名很短,它将保持原样。
人名_公司全名(公司行业)_公司地址及邮政编码_XXXXXXXXX_XX XXXXXXX.pdf
在接收方,附件文件名将变为:
Persons%20Name_Company%20Full%20Name%20%28Company%20Industry%28_Address%20of%20the%20Company%20with%20postal%20code_XXXXXXXXX_XX%20XXXXXXXXX.pdf
如果附件文件名在 70 个字符以内,它将保持原样,原始文件名。我的附件大多是pdf文件。
我尝试使用 utf8_decode()、htmlentities() 或尝试进行字符串替换,但它不起作用。
有谁知道可能是什么原因造成的?下面是 SwiftMailer 的发送函数。
//function to send emails
public function Send() {
//Create the Transport
$transport = $this->loadTransport();
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance($this->Subject)
->setFrom($this->From,$this->FromName)
->setTo($this->_addresses)
->setReplyTo($this->_replyto)
->setCc($this->_cc)
->setBcc($this->_bcc);
if($this->body) {
$message->addPart($this->body,'text/html');
}
if($this->altBody) {
$message->setBody($this->altBody);
}
if(!empty($this->_attachments)) {
foreach ($this->_attachments as $i => $file_attachment) {
$ori_filename = SwiftMailer::OriFilename($file_attachment);
$message->attach(Swift_Attachment::fromPath($file_attachment)->setFilename($ori_filename));
}
}
$result = $mailer->send($message);
$this->Clearaddresses();
$this->Clearattachments();
}
//function to break the path,get the filename,and decode it
public static function OriFilename($full_filename_path)
{
$ori_filename = explode('/',$full_filename_path);
return utf8_decode($ori_filename[3]);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)