CakePHP 3:通过电子邮件发送多个附件
CakePHP 3: Sending Multiple Attachments through A Email
我想在 CakePHP3.x 中发送电子邮件时附加多个文件。
这是我的数据并试过 像这样:
$files = [
(int) 0 => [
'getFileName' => '1568016275_452872.xlsx',
'getOriginalFileName' => 'DID Check.xlsx',
'destinationPath' => '\webroot\/upload/files/'
],
(int) 1 => [
'getFileName' => '1568016275_430107.csv',
'getOriginalFileName' => 'clists.csv',
'destinationPath' => '\webroot\/upload/files/'
]
]
$email->setAttachments($files)->send();
我也试过了,但只发送了电子邮件中的最后一个:
foreach($files as $file){
$email->setAttachments([$file['getOriginalFileName'] => $file['destinationPath'].$file['getFileName']])
}
无法理解,需要帮助并提前致谢。
Email::setAttachments()
覆盖有关以前附件的所有信息。因此,遍历您的文件并为每个文件调用 setAttachments()
将导致仅发送最后一个文件。
要解决此问题,您可以使用 Email::addAttachments()
,它只会添加附件而不覆盖当前数据,或者先准备好附件数组,然后使用 setAttachments()
设置一次。
更多信息:
我想在 CakePHP3.x 中发送电子邮件时附加多个文件。
这是我的数据并试过 像这样:
$files = [
(int) 0 => [
'getFileName' => '1568016275_452872.xlsx',
'getOriginalFileName' => 'DID Check.xlsx',
'destinationPath' => '\webroot\/upload/files/'
],
(int) 1 => [
'getFileName' => '1568016275_430107.csv',
'getOriginalFileName' => 'clists.csv',
'destinationPath' => '\webroot\/upload/files/'
]
]
$email->setAttachments($files)->send();
我也试过了,但只发送了电子邮件中的最后一个:
foreach($files as $file){
$email->setAttachments([$file['getOriginalFileName'] => $file['destinationPath'].$file['getFileName']])
}
无法理解,需要帮助并提前致谢。
Email::setAttachments()
覆盖有关以前附件的所有信息。因此,遍历您的文件并为每个文件调用 setAttachments()
将导致仅发送最后一个文件。
要解决此问题,您可以使用 Email::addAttachments()
,它只会添加附件而不覆盖当前数据,或者先准备好附件数组,然后使用 setAttachments()
设置一次。
更多信息: