我试图将存储在[storage / app / proof]中的图像附加到电子邮件中,但是,我得到...
而不是图像文件,这是我到目前为止所做的。
调节器
$user->accType = "TBC";
//stored as "proof/img_name.jpg" in DB
$user->proofLink = request()->file('proofFile')->store('proof');
$user->save();
\Mail::to('[email protected]')->send(new ConfirmAccount($user));
我究竟做错了什么?
嗨,你错过了附件mime类型..
attach('/path/to/file', [
'as' => 'name.pdf',
'mime' => 'application/pdf',
]);
你可以在https://laravel.com/docs/5.5/mail#attachments找到更多
希望这可以帮助。
该错误实际上是由不完整的路径引起的。
$location = storage_path("app/$user->proofLink");
正在返回“app /”而不是“app / records / img_name.jpg”。
为了解决这个问题,我编辑了ConfirmAccount.php如下:
public function __construct(User $user)
{
$this->URL = $user->proofLink;
}
public function build()
{
$location = storage_path("app/$this->URL");
return $this->view('emails.confirmaccount')->attach($location);
}