从本地存储添加电子邮件附件
Adding Email Attachments From Local Storage
我正在使用 laravel/lumen。我可以在我的存储目录中使用 Storage::disk("local")->put();
保存文件。但是现在我想将其中一些文件附加到电子邮件中并发送,这是通过作业完成的,我得到的错误是
lumen.ERROR: exception 'Swift_IoException' with message 'Unable to
open file for reading
现在我阅读了一些关于符号链接的内容,我试过了,但结果并没有改变,我仍然无法将存储文件夹中的文件附加到我的电子邮件中。
这是我的目录结构:
/home/xxxxxx/:
-example.app
--存储
---应用程序
----public
-public_html
--example.app
---存储
像这样附加文件:
foreach ($params["attachments"] as $attachment) {
$mail->attach($attachment["file"], [
'as' => $attachment["name"],
'mime' => $attachment["mime"]
]);
}
好吧,当您传递完整的 url 而不是文件的真实路径时,显然 swift 邮件程序失败了。不知道这个,不知道这是一个错误还是设计造成的。
您已经意识到 attach()
方法需要文件的完整路径。但是,其他人可能会发现知道如何实现这一点很有用。因此,如果您使用 local 商店的默认设置,您可以通过调用 storage_path()
帮助器来获取完整路径。这样:
/*
* This will return the full path to the file:
*
* /path/to/laravel/storage/app/attachment/path
*/
storage_path('app/' . $attachment['file']);
我正在使用 laravel/lumen。我可以在我的存储目录中使用 Storage::disk("local")->put();
保存文件。但是现在我想将其中一些文件附加到电子邮件中并发送,这是通过作业完成的,我得到的错误是
lumen.ERROR: exception 'Swift_IoException' with message 'Unable to open file for reading
现在我阅读了一些关于符号链接的内容,我试过了,但结果并没有改变,我仍然无法将存储文件夹中的文件附加到我的电子邮件中。
这是我的目录结构:
/home/xxxxxx/:
-example.app
--存储
---应用程序
----public
-public_html
--example.app
---存储
像这样附加文件:
foreach ($params["attachments"] as $attachment) {
$mail->attach($attachment["file"], [
'as' => $attachment["name"],
'mime' => $attachment["mime"]
]);
}
好吧,当您传递完整的 url 而不是文件的真实路径时,显然 swift 邮件程序失败了。不知道这个,不知道这是一个错误还是设计造成的。
您已经意识到 attach()
方法需要文件的完整路径。但是,其他人可能会发现知道如何实现这一点很有用。因此,如果您使用 local 商店的默认设置,您可以通过调用 storage_path()
帮助器来获取完整路径。这样:
/*
* This will return the full path to the file:
*
* /path/to/laravel/storage/app/attachment/path
*/
storage_path('app/' . $attachment['file']);