Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php swiftmailer smtp Yii2发送的附件中的xlsx文件已损坏_Php_Email_Yii2_Attachment_Swiftmailer - Fatal编程技术网

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

Php swiftmailer smtp Yii2发送的附件中的xlsx文件已损坏,php,email,yii2,attachment,swiftmailer,Php,Email,Yii2,Attachment,Swiftmailer,我正在使用Yii2和Swiftmailer发送一封带有附件的电子邮件。 当我试图在我的谷歌账户中打开一个文件时,谷歌写道该文件已损坏。我试图下载文件并打开它,但我的excel也告诉我该文件已损坏 但是,我试图在发送之前打开该文件,结果它完全打开了。我还尝试通过我的电子邮件客户端发送文件,然后文件也很好地打开了 我尝试使用不同的SMTP服务器,但没有任何变化 有什么问题吗 我附上密码 'mailer' => [ 'class' => 'yii\swiftmailer\M

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

但是,我试图在发送之前打开该文件,结果它完全打开了。我还尝试通过我的电子邮件客户端发送文件,然后文件也很好地打开了

我尝试使用不同的SMTP服务器,但没有任何变化

有什么问题吗

我附上密码

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


你的yii申请表中有翻译文件吗

我有一个类似的问题,我直接下载的XLSX文件在文件的末尾有两个额外的标签,这破坏了它。标签来自我的翻译文件

尝试将通过邮件获得的损坏文件与使用十六进制的文件进行比较,以找出差异

有关更多信息,请参见此:

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

$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(['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();
}