swiftmailer smtp Yii2发送的附件中的xlsx文件损坏

我正在使用Yii2和Swiftmailer发送带有附件的电子邮件。 当我尝试在我的Google帐户中打开文件时,Google写道该文件已损坏。我试图下载该文件并打开它,但是我的excel也告诉我该文件已损坏。

但是,我尝试在发送前打开文件,并且它可以完美打开。我还尝试通过电子邮件客户端发送文件,然后文件也很好地打开了。

我尝试使用其他SMTP服务器,没有任何变化。

可能是什么问题?

我附上代码。

'mailer' => [
        'class' => 'yii\swiftmailer\Mailer','transport' => [
            'class' => 'Swift_SmtpTransport','host' => 'XXX','username' => 'XXX','password' => 'XXX','port' => '465','encryption' => 'ssl',],

$emailManager = new EmailManager();
$mailer = $emailManager->actionSendfile($address,$filename,$subject,[
    'contentType' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',]);

public function actionSendfile($to,$filePathArray,$options = [])
{
    $send = Yii::$app->mailer->compose()
        ->setfrom(['noreply@example.com'])
        ->setTo($to)
        ->setSubject($subject)
        ->setHtmlBody("Some text");

        if(is_array($filePathArray)){
            foreach($filePathArray as $value){
                $send->attach($value,$options);
            }
        } else {
            $send->attach($filePathArray,$options);
        }


        return $send->send();
}
zhangwenxiu_1923_com 回答:swiftmailer smtp Yii2发送的附件中的xlsx文件损坏

您的yii应用程序中是否有翻译文件?

我有一个类似的问题,我直接下载XLSX文件,在文件末尾有两个附加选项卡,这损坏了它。这些选项卡来自我的翻译文件。

尝试将通过邮件获取的损坏文件与以十六进制工作的文件进行比较,以发现差异。

有关更多信息,请参见此:Why does Chrome add two tabs at the end of my xlsx file and by doing so,is corrupting the files?

(您也可以尝试使用OpenOffice Calc打开XLSX文件,它不像Excel那样挑剔,并且倾向于打开“损坏”的文件。)

本文链接:https://www.f2er.com/3068350.html

大家都在问