【问题标题】:How to attach image from storage in mail Laravel如何在邮件 Laravel 中附加存储中的图像
【发布时间】:2018-06-08 07:32:26
【问题描述】:

我正在尝试将存储在 [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('ehrs.office@gmail.com')->send(new ConfirmAccount($user));

确认帐户.php

我做错了什么?

【问题讨论】:

  • 也给出文件的mimtype。

标签: laravel smtp


【解决方案1】:

错误实际上是由不完整的路径引起的。

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

【讨论】:

    【解决方案2】:

    您好,您缺少附件 mime 类型..

                    attach('/path/to/file', [
                        'as' => 'name.pdf',
                        'mime' => 'application/pdf',
                    ]);
    

    您可以在https://laravel.com/docs/5.5/mail#attachments找到更多信息

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-01-24
      • 2020-11-10
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多