【问题标题】:sending mail with attachments in laravel 5.4 through mailgun通过 mailgun 在 laravel 5.4 中发送带有附件的邮件
【发布时间】:2018-03-21 20:35:52
【问题描述】:

我在使用 mailgun 发送邮件附件时遇到问题。

当我登录mailgun时,发送的邮件显示:

      "attachments": [],

这是我的代码:

      $location = Storage::get('attachments/'.$this-attachments->file_name);
      return $this->markdown('emails.create',["desc" => $this->mail->description])
           ->subject($this->mail->subject)
           ->attach($location);

当我返回 $location 时我得到了原始编码代码,所以我尝试使用 public_path() 但结果相同(“附件”:[],

我做错了吗?如何在邮件中获取附件?邮件正在通过,但没有附件。

感谢您的宝贵时间。

【问题讨论】:

  • 请检查 dd($location);以及哪个输出让你
  • 在 public_path() 上,我得到路径,即 C:drive,如果我使用 Storage::get(),我得到原始编码代码。
  • 那么 $location 的输出是什么,因为你得到的附件是空的,对吧?
  • ->attach() 应该有文件的路径吧?还是应该有文件本身?我都试过了。对我来说一切都很好,所以我认为可能有其他方法可以使用 mailgun 发送附件。 $location 为我提供了位于 C: drive 中的文件的路径。
  • 请点击此链接(expertphp.in/article/…) 希望这对你有用

标签: php laravel email mailgun


【解决方案1】:

storage_path()试试下面的代码:

$location = storage_path('attachments/'.$this-attachments->file_name);

return $this->markdown('emails.create',["desc" => $this->mail->description])
->subject($this->mail->subject)
->attach($location);

【讨论】:

  • 试过但没有用。所以我从使用 markdown 转向普通视图方法,它开始工作了。 -_- 这真的很烦人,我知道 Markdown 有什么问题。无论如何感谢您的帮助!
【解决方案2】:

你写的

$location = Storage::get('attachments/' . $this-attachments->file_name);

但应该是的

$location = Storage::get('attachments/' . $this->attachments->file_name);

您在$this-> 中忘记了>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 2012-12-23
    • 2017-07-02
    • 2021-10-10
    • 2021-05-12
    • 1970-01-01
    • 2011-06-08
    相关资源
    最近更新 更多