我正在使用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();
}