我正在使用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, $subject, $options = [])
{
$send = Yii::$app->mailer->compose()
->setFrom(['[email protected]'])
->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();
}
您的应用程序中是否有翻译文件?
我有一个类似的问题,我直接下载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那样挑剔,而且倾向于打开“损坏的”文件。)